The book Im learning perl from has very little information on the special variable $_ all it basically says is that if <STDIN> isnt assigned to a variable its assigned to $_ and it can be used with a foreach loop I've search some on the web but most of the tutorials I've run across have relativley little information on $_, although i've learned a bit more on it. one of the things I found out was that it works with a while loop, so I tried a few different ways of using it. but i cant figure out why it doesnt work for the second one and why the third one seems to be off by one every time it prints
print "first\n"; while (<STDIN>) { print; print "***\n"; last if(eof); } print "second\n"; while (<STDIN>!=eof) { print; print "***\n"; } print "\nthird\n"; while ((chomp($tst=<STDIN>))!=eof) {print $tst ; print "***\n"; }
I'm runing this on a windoze system. the first while statement works as I expect it to,basically you type something hit return it prints what you typed when you hit ctrl-z it exits.
the second one doesnt work, if you hit enter twice it exits out of the loop, from what I can guess is that $_ isn't being assigned, but no idea why it wont do the comparison .
The third one works buts its a lil off, after the second entry it prints stuff. from what I understand all 3 should produce the same output if someone could help me out and set me straight as to why the outputs are different I would greatly appreciate it

In reply to question about $_ and eof by wageslave

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.