Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Comparing parts of 2 strings in an array and deleting one

by hdb (Prior)
on Nov 29, 2013 at 14:22 UTC ( #1064958=note: print w/ replies, xml ) Need Help??


in reply to Comparing parts of 2 strings in an array and deleting one

Transforming your lists into a joined hash with list two first, so that list one will overwrite list two. Then transform back to list:

my %joinedList = map { /(.*)=(.*)/ } @list_two, @list_one; my @list = map { "$_=$joinedList{$_}" } keys %joinedList;

Disadvantage is that order is not preserved.

Update: it can be done even easier like this:

my @list = values %{{ +map { /(.*)=/; $1=>$_ } @list_two, @list_one }};

By tayloring the part /(.*)=/; $1=>$_ you can transform your data as you like.


Comment on Re: Comparing parts of 2 strings in an array and deleting one
Select or Download Code
Re^2: Comparing parts of 2 strings in an array and deleting one
by Amblikai (Beadle) on Nov 29, 2013 at 16:12 UTC

    I like this! Thanks!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (13)
As of 2015-07-06 14:12 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 (75 votes), past polls