Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Foreach loop help. Start from specific line

by blue_cowdawg (Prior)
on Oct 22, 2012 at 13:04 UTC ( #1000330=note: print w/ replies, xml ) Need Help??


in reply to Foreach loop help. Start from specific line

open SOURCE, "</path/to/my/file.txt"; my @lines = <SOURCE>; my $start = <whatever>; # set to where you want to start. foreach my $ix($start..$#lines) { my $line=$lines[$ix]; #Do the get request magic; }

another method:

use strict; use Tie::File; tie @lines,"Tie::File","< /path/to/my/file.txt" or die "$!"; my $start =<whatever>; foreach my $ix($start..$#lines) { my $line=$lines[$ix]; #Do the get request magic; }

The second method has the advantage of not loading all the file into memory.


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg


Comment on Re: Foreach loop help. Start from specific line
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1000330]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2014-08-31 00:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls