in reply to writing array as pairwise
Another solution using List::MoreUtils:
#!/usr/bin/env perl use strict; use warnings; use List::MoreUtils qw(natatime); use Data::Dump; my %HoPwy = ( foo => [qw(abe lincoln john doe freddy mac)], bar => [qw(homer simpson krazy kat)], ); for my $pwy ( sort keys %HoPwy ) { # my $pwy_arrayref = $HoPwy{$pwy}; # my $iterator = natatime 2, @$pwy_arrayref; my $iterator = natatime 2, @{ $HoPwy{$pwy} }; while ( my @pairs = $iterator->() ) { dd $pwy, \@pairs; } } __END__ karls-mac-mini:monks karl$ ./1114295.pl ("bar", ["homer", "simpson"]) ("bar", ["krazy", "kat"]) ("foo", ["abe", "lincoln"]) ("foo", ["john", "doe"]) ("foo", ["freddy", "mac"])
N.B.: Some variables names stolen from Re: writing array as pairwise by AnomalousMonk.
Update: ...shortened code a bit.
Best regards, Karl
«The Crux of the Biscuit is the Apostrophe»
|
|---|