Dear all,
I'm rather puzzled by the following problem with Perl:
#!/usr/bin/perl
# suck in whole file
undef $/;
$path="/path/to/file/file.txt";
open(H, "<$path") || die("Couldn't open file: $path");
while (<H> ) {
warn "got here";
$file=$_;
$length = length($file);
warn $length;
}
close(H);
exit(0);
I would assume that this sucks in the whole file, puts it into the variable $file, then determines its length and that's it. But that's not what happens. Here's the output I get on OSX:
got here at test.pl line 10, <H> chunk 1.
20508 at test.pl line 13, <H> chunk 1.
got here at test.pl line 10, <H> chunk 2.
0 at test.pl line 13, <H> chunk 2.
So in fact the loop is executed twice! The exact same code runs just as expected under Linux, i.e. with the loop only being executed once. What is going on here?
Thanks,
Sebastian
PS: I'm using the pre-installed Perl 5.6.0. The only thing I added to the base installation is the CPAN module and what's needed for communicating with MySQL (DBI, Data::ShowTable, and DBD::mysql)