Perl Gem, Filehandle Quoting

From Bilbo
Jump to: navigation, search

2006-07-21

This Perl code actually does not emit any warnings or errors!

#!/usr/bin/perl
use strict;
use warnings;
</table>

On further investigation, this code ...

#!/usr/bin/perl

use strict;
use warnings;

my @q = </table asdf>;

print "Length:  ", scalar(@q), "\n";
print "$_\n" foreach @q;

... generates this output ...

Length:  2
/table
asdf

Go figure.

While the notation <table> would emit an error (because the filehandle named "table" isn't open and thus can't be read from), if the junk inside the brackets is not a single bareword, Perl treats it more like qw-quoting, where it separates the inside on spaces and returns it as a list of strings. There Are Too Many Ways To Do It.