Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: question regarding slices

by duct_tape (Hermit)
on Nov 06, 2003 at 18:46 UTC ( #305115=note: print w/replies, xml ) Need Help??


in reply to question regarding slices

I can't think of how to do this, since it is a list instead of an array... it might not be possible. With lists you can use -1 to get the last element, but 2 .. -1 doesn't seem to work.

What about using grep to avoid the check for . and .. within the foreach?

foreach (grep { !/^\.\.?$/ } readdir(PRINT)) { # stuff }

I know this isn't what you asked for, but it is another solution. Personally I prefer having the check within the foreach loop like this:

next if (/^\.\.?$/);

Hope that helps.
Brad

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2019-10-22 17:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?