Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Okay, here we go again, except this time with the cartesian product (minus show duplicates), obtained with Math::Combinatorics::combine. Also, we had to set Data::Dumper::Deepcopy=1 to get a sane output from Data::Dumper.
use strict; use warnings; use Data::Dumper; use Math::Combinatorics qw(combine); my $HoA_show_characters = { flintstones => [ "fred", "barney" ], jetsons => [ "george", "jane"], }; # create all possible combis along the lines of: #[ # { "flinstones" => "fred" }, # { "flintsones" => "barney" } #]... etc my $AoH_show_characters = []; foreach my $show (keys %$HoA_show_characters) { foreach my $character ( @{ $HoA_show_characters->{$show} } ) { push @$AoH_show_characters, ( { $show => $character } ); } } #now make all possible combis of 2 from the above aoH. # but only accept combis from different shows my $AoH_show_characters_two_at_a_time; foreach my $a_of_hash_combis( combine( 2, @$AoH_show_characters ) ) { my $key1 = ( keys %{ $a_of_hash_combis->[0] } )[0]; my $key2 = ( keys %{ $a_of_hash_combis->[1] } )[0]; unless ( $key1 eq $key2) { #key 1 equals key 2 push @$AoH_show_characters_two_at_a_time, ( $a_of_hash_combis +); } } $Data::Dumper::Deepcopy = 1; print Dumper($AoH_show_characters_two_at_a_time);

In reply to Re: Converting HoA into AoH by tphyahoo
in thread Converting HoA into AoH by neversaint

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-03-19 02:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found