More stupid strict tricks!

J

J Krugman

Here's one more strict kink in the bug/feature duality manifold
(see also http://tinyurl.com/32blm ).

Apparently starting a variable's name with ^ cloaks it from strict:

use strict;
use warnings;

${^SNEAK} = "LOOK MA NO HANDS!!!\n";

print ${^SNEAK};

exit 0;
__END__


% perl stupid_strict_tricks.pl
LOOK MA NO HANDS!!!

Hmmmm... Is this "feature" documented anywhere? I was not able
to find mention of it in the strict manpage.

jill
 
B

Brad Baxter

Apparently starting a variable's name with ^ cloaks it from strict:

use strict;
use warnings;

${^SNEAK} = "LOOK MA NO HANDS!!!\n";

print ${^SNEAK};

exit 0;
__END__


% perl stupid_strict_tricks.pl
LOOK MA NO HANDS!!!

Hmmmm... Is this "feature" documented anywhere? I was not able
to find mention of it in the strict manpage.

In perlvar:

In particular, the new special "${^_XYZ}" variables are
always taken to be in package "main", regardless of any
"package" declarations presently in scope.

I didn't notice explicit reference to cloaking it from strict, but I
suspect that's the expected behavior.

Regards,

Brad
 
P

Paul Lalli

Here's one more strict kink in the bug/feature duality manifold
(see also http://tinyurl.com/32blm ).

Apparently starting a variable's name with ^ cloaks it from strict:

use strict;
use warnings;

${^SNEAK} = "LOOK MA NO HANDS!!!\n";

print ${^SNEAK};

exit 0;
__END__


% perl stupid_strict_tricks.pl
LOOK MA NO HANDS!!!

Hmmmm... Is this "feature" documented anywhere? I was not able
to find mention of it in the strict manpage.

perldoc perlvar

Finally, new in Perl 5.6, Perl variable names may be
alphanumeric strings that begin with control characters (or
better yet, a caret). These variables must be written in
the form "${^Foo}"; the braces are not optional. "${^Foo}"
denotes the scalar variable whose name is a control-"F"
followed by two "o"'s. These variables are reserved for
future special uses by Perl, except for the ones that begin
with "^_" (control-underscore or caret-underscore). No
control-character name that begins with "^_" will acquire a
special meaning in any future version of Perl; such names
may therefore be used safely in programs. $^_ itself,
however, is reserved.

Perl identifiers that begin with digits, control characters,
or punctuation characters are exempt from the effects of the
"package" declaration and are always forced to be in package
"main". A few other names are also exempt:

ENV STDIN
INC STDOUT
ARGV STDERR
ARGVOUT
SIG

In particular, the new special "${^_XYZ}" variables are
always taken to be in package "main", regardless of any
"package" declarations presently in scope.

Since the variable in question is automatically defined as belonging to
package main, it's equivalent of putting something like this in your
program:

$main::sneak = 'Look Ma no hands!';

which is also allowed by strict.


Paul Lalli
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top