Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: Deleting specific array elements

by salva (Canon)
on Nov 26, 2008 at 10:47 UTC ( [id://726066]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Deleting specific array elements
in thread Deleting specific array elements

That's very inefficient, O(N^2) worst case under the hood. If your data is so big it doesn't fits in memory, it is not a good solution either. Note also, that the grep solution is swap-friendly as it access memory in a sequential manner.

Anyway, if you want to minimize memory usage and still be O(N):

my $to = 0; for (@m) { $m[$to++] = $_ if $_ ne "\n"; } splice @m, $to;

Log In?
Username:
Password:

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

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

    No recent polls found