Message from discussion
static variable problem
Received: by 10.66.84.34 with SMTP id v2mr4017249pay.38.1353445909914;
Tue, 20 Nov 2012 13:11:49 -0800 (PST)
From: "Dave Saville" <d...@invalid.invalid>
Newsgroups: comp.lang.perl.misc
Subject: static variable problem
Date: Tue, 13 Nov 2012 13:38:07 +0000 (UTC)
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <fV45K0OBJxbE-pn2-l0DOsOblSoed@localhost>
Mime-Version: 1.0
Injection-Date: Tue, 13 Nov 2012 13:38:07 +0000 (UTC)
Injection-Info: mx04.eternal-september.org; posting-host="12f6f2e2d96e1c0fe9cc474ffed8cc8b";
logging-data="8766"; mail-complaints-to="ab...@eternal-september.org"; posting-account="U2FsdGVkX190FneAyAtlFlBU/IQ1zbTQ"
User-Agent: ProNews/2 V1.62.cp136-shl
Cancel-Lock: sha1:LmmEEyNXWsFeeG5NZBFKerIC9a8=
Path: s9ni2347pbb.0!nntp.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news.mccarragher.com!news.grnet.gr!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail
Bytes: 1446
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8bit
Please why does this throw 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
So $bar is private to foo - but you can't initialise it?
TIA
--
Regards
Dave Saville