You wrote on 05/19/2009 03:18 PM:
> 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
The best I can come up with on the fly would be something like this:
---
#!/usr/bin/perl
use strict;
use warnings;
my @test = ('A123C.11+002.001','FC32G.2-1.0','12B15.01+2145.15');
foreach my $item (@test)
{
print "$item\n\n";
($a,$n,$x,$y)) = $item =~ /(.{5})\.(\d\d?)[-+](\d{1,4})\.(\d{1,4})/;
my ($lengthx, $lengthy) = (length $x, length $y);
print "a = $a, n = $n, x = $x, y = $y, length x = $lengthx, length y =
$lengthy\n";
}
---
But the real experts can probably compress it much more still.
hth
Alex
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/