B
BZ
Hi!
Can anyone please explain to me why this code doesn't work? (it gives
a syntax error on the "print while..." line):
---- snip ----
#!/usr/bin/perl
use strict;
use warnings;
my %rec;
$rec{filename} = '/etc/fstab';
open($rec{fh},$rec{filename}) or die("$! while opening");
my @arr;
push @arr, { %rec };
# next line results in a syntax error:
print while (<$arr[0]->{fh}>);
close($rec{fh}) or die("$! while closing");
---- snip ----
If I change the <$arr[0]->{fh}> to readline($arr[0]->{fh}), it works
fine, and it also works fine if I put the filehandle in a scalar
variable first:
## this works fine again
my @arr;
push @arr, { %rec };
my $fh = $arr[0]->{fh};
print while (<$fh>);
Does anyone have a clue what's going on here?
Can anyone please explain to me why this code doesn't work? (it gives
a syntax error on the "print while..." line):
---- snip ----
#!/usr/bin/perl
use strict;
use warnings;
my %rec;
$rec{filename} = '/etc/fstab';
open($rec{fh},$rec{filename}) or die("$! while opening");
my @arr;
push @arr, { %rec };
# next line results in a syntax error:
print while (<$arr[0]->{fh}>);
close($rec{fh}) or die("$! while closing");
---- snip ----
If I change the <$arr[0]->{fh}> to readline($arr[0]->{fh}), it works
fine, and it also works fine if I put the filehandle in a scalar
variable first:
## this works fine again
my @arr;
push @arr, { %rec };
my $fh = $arr[0]->{fh};
print while (<$fh>);
Does anyone have a clue what's going on here?