Let's start by viewing while(<$filehandle>). This is actually a Perl abbreviation:
while (defined($_ = <$filehandle>)) {
print $_;
}
So, each time through the loop, you read the next line from the file, and if it is not defined, you will exit the loop. If defined, you continue. As you would expect, it whilewill loop until the condition is true.
You can see it by running perl -MO=Deparse program.pl. You can also check the documentation in Loop Control . The diamond operator is the same as the readline subroutine (it reads the next line from the file).
while ($_ = shift @array){print $_} , while. shift . , $_ , .
while ($var = @array){print $var}, $var . , @array . true, perlsyn
0, '0' "", () undef . .
, :
perl -le 'my @array = qw(a b c d e); my $var = @array; print $var'
5, 5 . while , 0 , , 1 .
:
my @array = qw(hi this is a test);
my $var;
while ( $var = @array ) {
print "$var\n";
}
2, , , .