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

Skipping records

Status
Not open for further replies.

rshandy

Technical User
Dec 26, 2003
91
US
I'm reading data from a flat file/txt file and if I encounter a certain string I want to skip to the next line I 'd also like to skip several lines until I get to next "identifier"

while (<INPUT>) {

chop;
$newdata=$_;

if ($newdata eq "XX") {
skip to next record / or
skip several records until $newdata eq "ZZ"

}
}

Thanks.
 
Use next to start the next iteration of the loop, e.g
next if $newdata eq "XX";
next unless $newdata eq "ZZ";

You should also be using chomp, not chop.
chomp removes the line terminator, whatever it is.
chop removes the last character of a line.

Please read the documentation on next, chomp and chop at or by using perldoc at the command prompt.
 
Thanks again for pointing me in the right direction. I didn't realize the differences in chop and chomp.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top