On 6/17/20 7:04 PM, Mike Flannigan 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

that is perfectly normal perl behavior. grabs in a regex return those grabs when in a list context. the two scalars will get the grabbed strings. that is a very common style and i am not sure why you would want to change it. the only comment i could make is that checking if a regex worked is usually important too. but you could check the definedness of one of the scalars for that.

uri
_______________________________________________
Houston mailing list
[email protected]
https://mail.pm.org/mailman/listinfo/houston
Website: http://houston.pm.org/

Reply via email to