On Wednesday, November 20, 2002, at 04:06  PM, Michael G Schwern wrote:
2.) my($key) forces list context but the result of a match can only be
stored in a scalar lvalue
3.) The result of a match is just a boolean, not the thing matched, so
$key would never have the unadorned macro name but that should be in $1.
Nope, the original code would work. Watch this:

[pe-242:~/bin/test] ken% cat match.pl
#!/usr/bin/perl -l
my ($matched) = "---foo---" =~ m/(\w+)/;
print "matched: $matched";

[pe-242:~/bin/test] ken% perl match.pl
matched: foo

The parentheses are *necessary* if you want the value returned. Otherwise you get only true/false:

[pe-242:~/bin/test] ken% cat match2.pl
#!/usr/bin/perl -l
my $matched = "---foo---" =~ m/(\w+)/;
print "matched: $matched";

[pe-242:~/bin/test] ken% perl match2.pl
matched: 1


-Ken



Reply via email to