That's because when you read from the file handle using the <> brackets, it
doesn't automatically put the line into $_.  You're just throwing away the
result.  print() does print $_, but in this case there's nothing in it.
BTW, my personal advice would be to avoid the implied $_ magick until you
are very familiar with Perl.  I mean, there's nothing wrong with small code,
but you should start by spelling everything out explicitly and then start
using the shortcuts if/when they make more sense and actually give you a
benefit.

-----Original Message-----
From: Chris San [mailto:[EMAIL PROTECTED]
Sent: Tuesday, June 24, 2003 11:25 PM
To: [EMAIL PROTECTED]
Subject: Simple doublt of $_ and print;


It is supose this code prints the first line of file text.txt (which is 
not empty), but it doesn't print anything.


$file = "text.txt";
open (file);
<file>;
print;
close (file);


I understood that  <file>;  gets a line (the first in this case) and, in 
this case, it puts the line in  $_ . Also,  print;  (without args) 
prints the content of $_ .

Any idea about it?


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to