Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Best way to remove elem of for loop

by sundialsvc4 (Abbot)
on Apr 24, 2014 at 15:38 UTC ( #1083633=note: print w/ replies, xml ) Need Help??


in reply to Best way to remove elem of for loop

I would suggest that you should loop through your list of entries, and push onto a separate list those which are directories.   Or, simply use a File::Find loop (instead of building an array of things, which consumes memory arbitrarily), and push directories onto the array as they are found.   (“Millions of files” would result in “a big phat array,” with the thrashing-induced slowdowns that such a thing might produce, whereas there probably aren’t “millions of directories.”)

Yes, it is perfectly reasonable to “mark things,” too, and then to loop back through looking for things that are not so marked.   Thus, your approach of zapping the names that are not directories is a legitimate approach.   However, I would set the element to undef, since you only need to get rid of the value that is now there; you need not conjure up an empty-string value to replace it.   The “marking” approach avoids the issue of diddling with an array while you are looping through one, which in general is never prudent to do.


Comment on Re: Best way to remove elem of for loop

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2014-12-21 11:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (104 votes), past polls