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

Re: Merging arrays

by jeffa (Chancellor)
on Jun 27, 2013 at 20:00 UTC ( #1041087=note: print w/ replies, xml ) Need Help??


in reply to Merging arrays

I am going to assume you have a typo in your second array definition (repeated 'acct4'). If that is a mistake then just use a hash slice:

my @array = qw( 111 222 333 444 555 888 ); my @array2 = qw( acct1 acct2 acct3 acct4 acct5 acct8 ); my %hash; @hash{@array} = @array2; use Data::Dumper; print Dumper \%hash;


jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)


Comment on Re: Merging arrays
Select or Download Code
Re^2: Merging arrays
by smls (Friar) on Jun 27, 2013 at 20:13 UTC
    I am going to assume you have a typo in your second array definition

    Good point.
    If the double "acct4" item in the original code is not a typo but rather intended to demonstrate special handling for duplicate entries, then the OP would need to explain how exactly such cases should be handled.

    One possibility would be to strip all duplicate items from the list before merging (e.g. using the uniq function from List::MoreUtils). However, whether that is the correct thing to do would depend on the exact specification of the intended outcome in the general case.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (15)
As of 2014-07-14 11:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (257 votes), past polls