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


In reply to Re: Encode::Detec::Detector: This is not an SV reference error by ww
in thread Encode::Detec::Detector: This is not an SV reference error by salmonix

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.