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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading lines from external files

Status
Not open for further replies.

Meatsim

Programmer
Oct 9, 2001
13
US
Hello folks, thanks for your help on earlier problems. I have another one - when reading data from a file, how do you skip to the next line? Right now I have a

while(<INPUTFILE>)

solution going, but is there a command that loads the next line of the file, unrelated to while loops? Like nextline(<INPUTFILE>) or something?

Thanks,
Meatsim
 
Sure, just

while(<INPUTFILE>)
{
#do your stuff
if(youWannaSkip)
{
$junk = <INPUTFILE>
}
}
Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
 
Or you can just say &quot;next;&quot; inside of the loop. For example, this will skip all blank lines and print the rest:
Code:
while ( <INPUTFILE> ) {
   next if /\A\s*\Z/;
   print;
}
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
One quick question - in mbaranski's code snippet, is the next line of <INPUTFILE> actually stored in $junk, or is whatever keeps track of <INPUTFILE> just scrolled forward a line?

Thanks!
-Meatsim
 
The line '$junk = <INPUTFILE>;' says the following:

Take the next line from the file handle 'INPUTFILE' and store it in $junk.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top