[ Remailed to the list (sorry about that, Rob) ]

On Dec 13, 2003, at 9:07 AM, Rob Dixon wrote:
As a final thought, I would point out that $_ is a package ('our')
variable, but is localised by 'map', 'grep', 'foreach (LIST)' and
'while (<>)'.

Actually, $_ isn't localized by 'while(<>)':


    % echo test | perl -le 'for ("const") { print while <> }'
        Modification of a read-only value attempted at -e line 1.

Which occasionally jumps up and bites people.

And for the trivia buffs: another interesting thing about the special
package variables (it's the globs/symbols that are actually special,
see below) is that they're always in package "main".

    % perl -le '{ package X; $inc++ } print "[$inc]"'
    []
    % perl -le '{ package X; $INC++ } print "[$INC]"'
    1

The exception to this is when an our() declaration (which is a
lexically scoped symbol, remember) hides the special global.

    % perl -le '{ package X; our $INC = 1 } print "[$INC]"'
    []

--
Steve


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to