rkg has asked for the wisdom of the Perl Monks concerning the following question:

This is a simple strange question. Activestate 5.6.1 633. I have the following code:
use strict; use warnings; open (FH, "save.htm") or die; while (<FH>) { print $., $_; }
The file "save.htm" is almost 2 million bytes, a screen of content from WWW::Mechanize ($m->content). The file opens fine in notepad or emacs. The file has multiple lines of data. But the code about simply prints "1" -- it only finds one line, and $_ doesn't seem populated.

I am probably missing something dumb here -- can someone set me back on course?

thanks

rkg

Replies are listed 'Best First'.
Re: Puzzled about <F>
by Corion (Patriarch) on May 13, 2003 at 17:18 UTC

    Most likely, a ^Z is "hidden" in your data, which makes Perl under Win32 stop reading the file. The remedy (and always good practice) would be to use binmode before reading from the file :

    use strict; use warnings; open (FH, "save.htm") or die "Couldn't open 'save.htm' : $!"; binmode FH; while (<FH>) { print $., $_; }
    perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web
Re: Puzzled about <F>
by Thelonius (Priest) on May 13, 2003 at 17:15 UTC
    I've never had any problems with ActivePerl reading files with either kind of line ending. One possibility (although it seems unlikely given how the file was created) is that there is a ^Z on the first line of the file. Try binmode(FH) after the open and see if that helps.
Re: Puzzled about <F>
by dragonchild (Archbishop) on May 13, 2003 at 17:11 UTC
    newlines on windows and unix (and mac) are different. Try changing $\ to "\n" or "\r\n" and seeing if that helps.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.