in reply to More Scope related questions.

G'day curiousmonk,

Your question appears to have been answered in the responses you've already received. I might just point out that $a and $b were poor choices for your examples as they're special variables that don't require declaration. Here's an excerpt from perlvar:

  • $a
  • $b
    Special package variables ... Because of this specialness $a and $b don't need to be declared (using use vars, or our()) even when using the strict 'vars' pragma. ...

-- Ken

Replies are listed 'Best First'.
Re^2: More Scope related questions.
by curiousmonk (Beadle) on Mar 29, 2013 at 07:22 UTC

    Thanks, this was one thing I didn't know about. It just all boils down to reading documentation properly

    Just as you said

    $ perl -e 'use strict;use Data::Dumper;{my @c=(0..10);$d=\@c} print Du +mper $d' Global symbol "$d" requires explicit package name at -e line 1. Global symbol "$d" requires explicit package name at -e line 1.

    Doesn't work, but

    $ perl -e 'use strict;use Data::Dumper;{my @a=(0..10);$b=\@a} print Du +mper $b' $VAR1 = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];

    Does