develooper Front page | perl.beginners | Postings from March 2002

Re: Transfer a file via FTP

Thread Previous
From:
Jenda Krynicky
Date:
March 29, 2002 08:21
Subject:
Re: Transfer a file via FTP
Message ID:
3CA4A27A.15068.A00288@localhost
From:           	Ahmed Moustafa <amoustafa@pobox.com>
> Jenda Krynicky wrote:
> > Anyway when reading file you don't need any end of line character,
> > the system KNOWs how long is the file at the moment and <FILEHANDLE>
> > will return undef if you've read all there is.
> 
> I didn't get what you meant by "<FILEHANDLE> will return undef if
> you've read all there is"; would you explain more, please?

if you open a file and the read it line by line by

	$line = <FILEHANDLE>;

then as soon as you have read all lines in the file, the $line will get 
set to undefined. That is if you want to read and process all lines in 
a file you do this:

	open FILEHANDLE, "< $filename"
		or die "Cannot open $filename : $!\n";

	while (defined ($line = <FILEHANDLE>)) {
		do whatever you like with $line
	}
	# now we've read "all there is" = "all data in the file"
	close FILEHANDLE;

The file doesn't have to end with any special character, and most 
likely will not.

Jenda

=========== Jenda@Krynicky.cz == http://Jenda.Krynicky.cz ==========
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain
I can't find it.
					--- me

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About