A straightforward question I hope.

Can someone explain why the following code runs without a hitch:

#!C:/strawberry/perl/bin/perl.exe
use strict;
use warnings;

my $testvar = "TEST";
&testsub1();

sub testsub1 {
print "The following should read \"TEST\": $testvar \n";
}



... while this throws up "Global symbol $testvar" requires explicit package
name ..." etc. etc.

#!C:/strawberry/perl/bin/perl.exe
use strict;
use warnings;

sub testsub1 {
print "The following should read \"TEST\": $testvar \n";
}

my $testvar = "TEST";
&testsub1();



I'm guessing that I'm misunderstanding how Perl compiles the code.  I'm
reading through Learning Perl and Programming Perl but I've either missed
something, or have yet to read far enough.  Any explanation would be
appreciated.

OWEN.

Reply via email to