Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Static variable problem (http://www.velocityreviews.com/forums/t954475-static-variable-problem.html)

Dave Saville 11-13-2012 03:15 PM

Static variable problem
 
Apologies if this appears twice but I have not seen it and my sent
posts folder does not have a copy - but I would swear I hit send :-)


Please can someone explain why the following throws an error?

[T:\tmp]cat try.pl
use strict;
use warnings;

foo("Hello World");
exit;
{
my $bar = 1;

sub foo
{
my $a = shift;
print "$bar $a\n"; <== line 12
return;
}
}

[T:\tmp]try.pl
Use of uninitialized value in concatenation (.) or string at try.pl
line 12.
Hello World

$bar is private to foo - yes? So you can't initialize it?
--
Regards
Dave Saville


All times are GMT. The time now is 12:09 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.