in reply to Capture groups
Are you trying to use Perl 5.10 and the smart match operator? Here's the solution written with named captures, the nifty new 5.10 features that mean you never have to think about $1, $2, and so on. The names become keys in the new hash %+, and the matched text are the values:
#!/usr/local/bin/perl5.10.0 use 5.010; my $text = "Grand Canyon 70%"; $text ~~ / (?<name> .*\S ) \s+ (?<percent> \d\d% ) /x; use Data::Dumper; print Dumper( \%+ )
The output automatically labels your values:
$VAR1 = { 'percent' => '70%', 'name' => 'Grand Canyon' };
Here's the boring Perl 5.8 way:
#!/usr/bin/perl my $text = "Grand Canyon 70%"; $text =~ / ( .*\S ) \s+ ( \d\d% ) /x; print <<"HERE"; 1: $1 2: $2 HERE
|
---|
In Section
Seekers of Perl Wisdom