Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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

by hdb (Monsignor)
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.

Replies are listed 'Best First'.
Re^2: Comparing parts of 2 strings in an array and deleting one
by Amblikai (Scribe) 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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2017-11-25 08:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (355 votes). Check out past polls.

    Notices?