Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fast way to get file length?

Status
Not open for further replies.

subotai

Programmer
Jun 26, 2002
6
DE
Greetings!

Probably a simple question:
How can i determine the file length in bytes of a simple text file? Something with a while (! eof(FILE)) - loop, a getc(FILE) inside, incrementing a counter? I keep producing eternal loops with this!
Please forgive me, (Subotai==newbie)=1 :-D

Thankful for any help,
Subo
 
OUCH!

Im really sorry, just found the stat(FILE); function.

Apologies to everyone who wasted time on this!
 
A more standard way to read lines from a file in Perl is
Code:
while (<FILE>) {

     # the line read in is stored in the variable $_
     print &quot;$_&quot;;
}
or a long-hand way to do it that is perhaps more instructive
Code:
while ( defined ($line = <FILE>) ) {
     # do something with $line here like
     print $line;
}

jaa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top