amir_e_a has asked for the wisdom of the Perl Monks concerning the following question:
And i need the list:$string = "bla bla bla [[en:English]][[de:German]][[ga:Irish]] bla bla + bla";
I can do this:qw(en de ga);
And then i get qw(en de ga) in @matches, but that's because i have only one pair of capturing brackets, which is a limitation. If i do, for example:@matches = ( $string = m/\[\[(en|de|ga):.+?]\]/g );
Then i'll get qw(en English de German ga Irish). Is there a clever way to get a list of all the results from one pair of capturing brackets? I tried using Perl 5.10's named captures and %-. Either it can't be done this way or i am doing incorrectly. I tried this:@matches = ( $string = m/\[\[(en|de|ga):(.+?)]\]/g );
i get this output:my $string = 'bla bla [[en:English]][[de:German]][[ga:Irish]] bla bla' +; if (my @matches = ($string =~ m/\[\[(?<lang>en|de|ga):(.+?)\]\]/g)) { say 'matches'; say 'matches: ', Dumper(\@matches); say 'minus : ', Dumper(\%-); say 'plus : ', Dumper(\%+); }
You see - only ('ga'), but is there some way to get:matches matches: $VAR1 = [ 'en', 'English', 'de', 'German', 'ga', 'Irish' ]; minus : $VAR1 = { 'lang' => [ 'ga' ] }; plus : $VAR1 = { 'lang' => 'ga' };
Thanks in advance for any help.$VAR1 = { 'lang' => [ 'en', 'de', 'ga' ] };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Getting a list of captures in Perl 5.10
by BrowserUk (Patriarch) on May 24, 2008 at 15:52 UTC | |
by carol (Beadle) on May 24, 2008 at 23:07 UTC | |
by BrowserUk (Patriarch) on May 25, 2008 at 05:23 UTC | |
by amir_e_a (Hermit) on May 24, 2008 at 16:47 UTC | |
|
Re: Getting a list of captures in Perl 5.10
by moritz (Cardinal) on May 24, 2008 at 15:17 UTC | |
|
Re: Getting a list of captures in Perl 5.10
by duelafn (Parson) on May 25, 2008 at 12:49 UTC |