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.
-
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.
|