in reply to How to use __DATA__ efficiently, help!
#do{$data = $data . $_ } while (<DATA>); #gives a uninitialized value +in concatenation
You get the "uninitialized value" warning because the do {...} executes once before a value is being assigned to $_. Just turn it around:
my $data; while (<DATA>) { $data .= $_ }
BTW, note that $data .= "foo" (or $data = $data . "foo" for that matter) is a special case that does not generate an "uninitialzed value" warning, even if $data is undefined initially:
$ perl -we 'my $foo; $foo = $foo . "foo"' # no warning
while this does, of course:
$ perl -we 'my $foo; my $bar = $foo . "foo"' Use of uninitialized value $foo in concatenation (.) or string at -e l +ine 1.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How to use __DATA__ efficiently, help!
by Anonymous Monk on Feb 09, 2011 at 19:26 UTC | |
by Anonyrnous Monk (Hermit) on Feb 09, 2011 at 19:37 UTC | |
by belden (Friar) on Feb 10, 2011 at 16:30 UTC | |
by Anonyrnous Monk (Hermit) on Feb 10, 2011 at 17:32 UTC | |
by Anonymous Monk on Feb 09, 2011 at 19:56 UTC | |
by Anonyrnous Monk (Hermit) on Feb 09, 2011 at 20:02 UTC |