Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Cannot skip first lines in array

by periapt (Hermit)
on Oct 20, 2004 at 12:42 UTC ( #400842=note: print w/ replies, xml ) Need Help??


in reply to Cannot skip first lines in array

Assuming that @rebasefile is an array you can skip the first 10 indices in a couple of ways

foreach (@rebasefile[10..$#rebasefile]){ # skips the first ten automat +ically next if(/^\s*$/); ... }
# alternately if you don't want the overhead of creating an array slice
foreach (@rebasefile){
next for (0..9); # of course, this has overhead of its own
next if(/^\s*$/);
...
}
I haven't checked which implementation is faster. I suspect that for just 10 elements, there is a non-measurable difference. If you were ignoring 100 or more elements, the slice is probably more efficient.

Update:

Ignore the second loop. Never get smug before your first cup of coffee.

PJ
use strict; use warnings; use diagnostics;


Comment on Re: Cannot skip first lines in array
Download Code
Re^2: Cannot skip first lines in array
by dave_the_m (Parson) on Oct 20, 2004 at 12:53 UTC
    foreach (@rebasefile){ next for (0..9); # of course, this has overhead of its own next if(/^\s*$/); ... }
    That doesn't skip the first 10 elements, it just calls an empty loop 10 times for each element.

    Dave.

Re^2: Cannot skip first lines in array
by Taulmarill (Deacon) on Oct 20, 2004 at 15:24 UTC
    i don't think next for (0..9); is working the way you want.
    however, the first foreach loop should work just fine.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2014-08-01 00:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (255 votes), past polls