in reply to close ARGV inside a while
I'm not sure why you think it's strange behaviour; it seems logical to me.
You are putting $0 (the name of the current file) into @ARGV, and then reading from that file. When you close the file with close ARGV, you've already read one line, which is in $_. So when you do:
print '.',$_;
you are simply printing out a period '.', concatenated with the first line of the Perl script itself.
Try taking out the line close ARGV; and the whole program will be printed:
#!/usr/bin/perl -w use strict; use warnings; #prints one line and bails out @ARGV = ( $0 ); while (<>) { # close ARGV; print $_; } # Output #!/usr/bin/perl -w use strict; use warnings; #prints one line and bails out @ARGV = ( $0 ); while (<>) { # close ARGV; print $_; }
|
|---|