Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1083633]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2018-06-21 12:47 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (118 votes). Check out past polls.