Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Cannot skip first lines in array

by periapt (Hermit)
on Oct 20, 2004 at 12:42 UTC ( [id://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;

Replies are listed 'Best First'.
Re^2: Cannot skip first lines in array
by dave_the_m (Monsignor) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://400842]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-25 16:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found