in reply to Perl Idioms Explained - @ary = $str =~ m/(stuff)/g
All three cases return the same result. Explanation for case 1 is covered in earlier posts. However I am puzzled by the use of parentheses in the example, so I added ?: to it to tell the regular expression to forget the value in the capture parentheses if any. The result is the same! So the regular expression is not acting on the $1 variable captured by the parentheses at all. So I eliminated the parentheses totally, I still get the same result.$str = "Ab stuff Cd stuff Ef stuff"; # case 1 @ary1 = $str =~ m/(stuff)/g ; # case 2 @ary2 = $str =~ m/(?:stuff)/g ; # case 3 @ary3 = $str =~ m/stuff/g ; print "\@ary1 = @ary1\n"; print "\@ary2 = @ary2\n"; print "\@ary3 = @ary3\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Perl Idioms Explained - @ary = $str =~ m/(stuff)/g
by antirice (Priest) on Sep 16, 2003 at 02:08 UTC | |
Re: Re: Perl Idioms Explained - @ary = $str =~ m/(stuff)/g
by tachyon (Chancellor) on Sep 16, 2003 at 04:44 UTC |