I am trying to understand the correct way to define
variables and their scope.

Here are two simple PERL  ( test1.pl and test2.pl
)scripts. test1.pl work fine, while test2.pl does not.

Would appreciate any help in understanding why
test2.pl is complaining about "Global symbols"

Thanks

PN


test1.pl
========
#!/usr/bin/perl -w
use strict;

my $user = $ENV{USER};
my $test = "Perl";

print " User : $user\n";
print " Test  : $test\n";

test2.pl
========
#!/usr/bin/perl -w
use strict;

$user = $ENV{USER};
$test = "Perl";

print " User : $user\n";
print " Test  : $test\n";

The only difference in code is this:

In test1.pl, the variables are defined using "my",
while in test2.pl, the variables are defined without
use of the keyword "my".

Here are the results of my attempts at running the
scripts :

% perl -c test1.pl
  test.pl syntax OK

% perl -c test2.plperl -c test2.pl
Global symbol "user" requires explicit package name at
test2.pl line 5.
Global symbol "test" requires explicit package name at
test2.pl line 6.
Variable "$user" is not imported at test2.pl line 8.
Global symbol "user" requires explicit package name at
test2.pl line 8.
Variable "$test" is not imported at test2.pl line 9.
Global symbol "test" requires explicit package name at
test2.pl line 9.
test2.pl had compilation errors.

  




__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to