A crude one

($part,$unit,$x,$y,$xlen,$ylen) = ($1,$2,$3,length($4),length($5))
if ($string =~ /(^\S{5})\.(\d{2})([+-])(\d+)\.(\d+)$/);



-----Original Message-----
From: Dan Fish [mailto:[email protected]] 
Sent: 19 May 2009 14:18
To: [email protected]
Subject: Simple regex question

Simple question for the regEXperts out there...

I have a string that is always in the format:  aaaaa.nn+x.y 

a is always 5 chars 
n can be 1 or 2 digits
x can be +/- (with sign), 1-4 digits
y is always positive (no sign), 1-4 digits


Some examples:
        A123C.11+002.001
        FC32G.2-1.0
        12B15.01+2145.15
        
I need all 4 pieces and the length of x & y. The following works:

my $id= "A123C.11+002.001";

my @tmp = split(/[\.+-]/,$id);
my $part = $tmp[0];
my $unit = $tmp[1];
my $x = $tmp[2];
my $y = $tmp[3];
my $xlen = length $tmp[2];
my $ylen = length $tmp[3];

but in my quest for understanding regex, I'm always looking for more
elegant
(obfuscated :-) code... 
Anybody have a good one-liner for this?

my ($part,$unit,$x,$y,$xlen,$ylen) = /* Some obfuscated code here.. */


Thanks!
-Dan

---
[email protected]
(To reply via email, remove 'reverse(nospam)' in address.  Spambots are
getting waaaay too smart nowadays...:-) 


-- 
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/



This email is from the Press Association.  For more information, see 
www.pressassociation.com.
This email may contain confidential information.  
Only the addressee is permitted to read, copy, distribute or otherwise use this 
email or any attachments.  
If you have received it in error, please contact the sender immediately.  
Any opinion expressed in this email is personal to the sender and may not 
reflect the opinion of the Press Association.
Any email reply to this address may be subject to interception or monitoring 
for operational reasons or for lawful business practices.


--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to