#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.
In reply to Re: How to use __DATA__ efficiently, help!
by Anonyrnous Monk
in thread How to use __DATA__ efficiently, help!
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |