coolmichael has asked for the wisdom of the Perl Monks concerning the following question:
I am using a regex to extract some numbers from a string, to build an array of numbers. However, I don't seem to be able to use < and > to compare the numbers. How can I (or can I) force a numeric context on to $2 and $3 in the annonymous array?
Thank you.my @list = qw(M4568-51 M4568-5 M8954-89 M4568-56 H1234-6 H0012-45); my @big = map { m/^(\w)(\d{4})-(\d{1,2})$/ or die "bad data: $!\n"; [$_, $1, $2, $3]; } @list; print Dumper(@big); ----------------------results (tidied up a bit)------- $VAR1 = ['M4568-51', 'M', '4568', '51']; $VAR2 = ['M4568-5', 'M', '4568', '5' ]; $VAR3 = ['M8954-89', 'M', '8954', '89']; $VAR4 = ['M4568-56', 'M', '4568', '56']; $VAR5 = ['H1234-6', 'H', '1234', '6' ]; $VAR6 = ['H0012-45', 'H', '0012', '45'];
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: extracting numbers with a regex
by belg4mit (Prior) on Dec 05, 2001 at 08:36 UTC | |
Re: extracting numbers with a regex
by dws (Chancellor) on Dec 05, 2001 at 09:13 UTC | |
by Fastolfe (Vicar) on Dec 05, 2001 at 11:25 UTC |
Back to
Seekers of Perl Wisdom