scripting - How does use of "my" keyword distiguish the results in perl? -
scripting - How does use of "my" keyword distiguish the results in perl? -
i dont understand how "my" keyword works here. perl script.
$line = ' sdfaad(asdvfr)'; code1:
if ($tmp = $line =~ /(\(\s*[^)]+\))/ ) { print $tmp; } outputs:
1 code2:
if (my ($tmp) = $line =~ /(\(\s*[^)]+\))/ ) { print $tmp; } outputs:
(asdvfr) why 2 outputs different? have utilize of my?
it not my makes difference, scalar/list context. braces around $tmp imposing list context,
if (($tmp) = $line=~ /(\(\s*[^)]+\))/ ) # braces makes difference, not 'my' while my declares variable lexical scoped one.
perl scripting pattern-matching output string-matching
Comments
Post a Comment