Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Foreach loop help. Start from specific line

by blue_cowdawg (Monsignor)
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 avoiding work at the Monastery: (11)
As of 2014-09-17 16:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (91 votes), past polls