uvnew has asked for the wisdom of the Perl Monks concerning the following question:

Hey guys. I need to loop through a large file line by line, then on every first instance I find what I look for I want to skip to the end of the file to avoid unnecessary readings (or alternatively return to the file start). Would thank you for any hint.

Replies are listed 'Best First'.
Re: Skipping to file end
by davorg (Chancellor) on Feb 13, 2007 at 11:31 UTC
Re: Skipping to file end
by johngg (Canon) on Feb 13, 2007 at 11:17 UTC
    It sounds like you want to stop reading the file once you have found what you are looking for. If you read the file in a while loop you can break out of the loop with last. Like this

    while (my $line = <$inputFH> ) { next unless $line =~ m{some pattern}; # Process wanted line here ... last; # Break out of while loop }

    I hope this helps you.

    Cheers,

    JohnGG