in reply to Encode::Detec::Detector: This is not an SV reference error
To expand on Khen1950fx's correct observation, some vars are customarily or (in this case) inherently allowed in specific cases only.
"Customarily" applies to the likes of $a and $b -- are allowed elsewhere, but, by convention, are reserved for use in sorting. OTOH, $1 is reserved for use in regex capture.
perl -e "use strict; my $1='foo'; if ($foo=~/(f)/){print $1;}" Can't use global $1 in "my" at -e line 1, near "my $1" Global symbol "$foo" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors.
Note the problem with $foo above... despite which the attempted illegal use of $1 had precedence with the compiler's error checking.
And just to beat this deceased equine a bit more, eliminating the $foo issue (and use strict;) leads to this:
perl -e "my $1='foo'; if ($1=~/(f)/){print $1;}" Can't use global $1 in "my" at -e line 1, near "my $1" Execution of -e aborted due to compilation errors.
In short, use meaningful variable names... and learn which (tempting) low-keystroke vars are meaningful to Perl.
Updated penultimate para to acknowledge/highlight the elimination of strict
|
|---|