Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: Getting the hash in this format

by Athanasius (Archbishop)
on Aug 23, 2014 at 12:21 UTC ( [id://1098403]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Getting the hash in this format
in thread Getting the hash in this format

Sure, but then you might be better off with another array, rather than a hash as the node title requested:

#! perl use strict; use warnings; my @array1 = qw(red blue green); my @array2 = qw(black orange white); my @params; push @params, shift(@array1) . ':' . shift(@array2) while @array1; print join(',', @params), "\n";

Output:

22:16 >perl 977_SoPW.pl red:black,blue:orange,green:white 22:20 >

Update: The above removes the elements from @array1 and @array2. For a non-destructive solution, we can again use pairwise:

#! perl use strict; use warnings; use List::MoreUtils 'pairwise'; use Data::Dump; my @array1 = qw(red blue green); my @array2 = qw(black orange white); my @params = pairwise { $a . ':' . $b } @array1, @array2; dd \@array1; dd \@array2; print join(',', @params), "\n";

Output:

23:51 >perl 977_SoPW.pl ["red", "blue", "green"] ["black", "orange", "white"] red:black,blue:orange,green:white 23:51 >

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^4: Getting the hash in this format
by ash_86 (Initiate) on Aug 23, 2014 at 13:30 UTC
    Great! Thanks for the help.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-03-29 00:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found