Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Removing certain lines from array

by arkturuz (Curate)
on Jul 30, 2013 at 09:17 UTC ( #1046981=note: print w/ replies, xml ) Need Help??


in reply to Removing certain lines from array

How about this approach:

my @array = ( "hello 1234 5698 7458", "hi 1457 7459 6214", "good_day 1458", "hi 1258 3658", "good_morning 4758", "hi 1453", ); # count all occurences my %freqs; for my $elem (@array) { my ($word) = $elem =~ /^(\w+)/; $freqs{$word}++; } # remove all multifrequent words my @new_array; for my $elem (@array) { my ($word) = $elem =~ /^(\w+)/; unless ($freqs{$word} > 1) { push @new_array, $elem; } }
edit: corrected - element needs to be removed


Comment on Re: Removing certain lines from array
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2015-07-07 13:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (88 votes), past polls