Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Foreach loop help. Start from specific line

by blue_cowdawg (Monsignor)
on Oct 22, 2012 at 13:04 UTC ( [id://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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-23 22:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found