[pm-h] Perl Code

Uri Guttman uri at stemsystems.com
Wed Jun 17 23:13:00 PDT 2020


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


More information about the Houston mailing list