develooper Front page | perl.perl5.porters | Postings from May 2012

[perl #112934] Referencing undefined $a or $b inside eval "..." is silently permitted under use strict.

Thread Previous
From:
Father Chrysostomos via RT
Date:
May 14, 2012 17:49
Subject:
[perl #112934] Referencing undefined $a or $b inside eval "..." is silently permitted under use strict.
Message ID:
rt-3.6.HEAD-4610-1337042933-1386.112934-15-0@perl.org
On Mon May 14 17:23:59 2012, jimav wrote:
> 
> References to undefined variables $a or $b do not cause an
> error or warning inside eval "...".
> 
> #!/usr/bin/perl
> use strict; use warnings;
> 
> for my $varname ('a' .. 'z') {
>    my $value = eval " \$${varname}->[42] ";
>    if ($@) {
>      print "EVAL ERROR: $@\n";
>      exit 1;
>    }
>    print "No error for varname '${varname}', result is ",
>          (defined $value ? $value : 'undef'), "\n";
> }

From perlvar:

=item $a

=item $b
X<$a> X<$b>

Special package variables when using C<sort()>, see L<perlfunc/sort>.
Because of this specialness C<$a> and C<$b> don't need to be declared
(using C<use vars>, or C<our()>) even when using the C<strict 'vars'>
pragma.  Don't lexicalize them with C<my $a> or C<my $b> if you want to
be able to use them in the C<sort()> comparison block or function.


-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: new
https://rt.perl.org:443/rt3/Ticket/Display.html?id=112934

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About