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

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

by hdb (Parson)
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 (Sexton) 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 exploiting the Monastery: (4)
As of 2014-04-19 18:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (483 votes), past polls