Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Well, I noticed that in your %HoH, you're using a range operator for the array ref. Assuming your really do want a range and that the 3rd and 4th values are always in the correct order, you can do this:

#!/usr/local/bin/perl use strict; use warnings; use Data::Dumper; $Data::Dumper::Indent = 1; my @AoA = ( [qw/10 27 17 20/], [qw/10 24 22 25/], [qw/11 25 24 25/], [qw/11 26 19 20/], ); my %HoH; foreach my $aref (@AoA) { my ($key1, $key2) = splice @$aref => 0, 2; @$aref = $aref->[0] .. $aref->[1]; # this creates the range $HoH{$key1}{$key2} = $aref; } print Dumper \%HoH;

If the range operator was a typo, you can delete the line I marked with the comment. If the order of the 3rd and 4th elements are not guaranteed, then it's trivial to reverse 'em.

Of course, depending on your data, you may or may not want sanity checking in there.

Cheers,
Ovid

New address of my CGI Course.


In reply to Re: Hash of Hashes of Arrays by Ovid
in thread Hash of Hashes of Arrays by Miguel

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 drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-24 02:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found