Mike, The behavior that you are describing is covered in Perl regular expressions tutorial at https://metacpan.org/pod/distribution/perl/pod/perlretut.pod#Extracting-matches .
I personally leverage this a lot in the code that I write - especially to capture all occurrences of something into an array. In fact, I have gotten into the habit of trying to write my code in such a way to try to avoid using the regex variables like $1 and $2. And Uri has a very good point about needing to include some way to verify that the regex actually matched and returned values. Not having that has caused me headaches with trying to figure out what went wrong with my code. John Ellyson On Wed, Jun 17, 2020 at 6:04 PM Mike Flannigan <[email protected]> wrote: > > Recently I found this bit of code that I wrote > long ago. I am a little surprised this works > ($1 and $2 get transferred to the scalars). > I don't write that way anymore, but I am > leaving it that way in this program. > > > use strict; > use warnings; > > my $test = 'abcdefgh'; > my ($latm, $longm) = $test =~ /(ab).*(fg)/i; > print "$latm, $longm\n"; > > > Prints this: > ab, fg > > > > Mike > _______________________________________________ > Houston mailing list > [email protected] > https://mail.pm.org/mailman/listinfo/houston > Website: http://houston.pm.org/ >
_______________________________________________ Houston mailing list [email protected] https://mail.pm.org/mailman/listinfo/houston Website: http://houston.pm.org/
