Just iterate over the keys of your data-hash, and derefence the array.
for (keys %conductordata){ print OUT @{$conductordata{$_}}; }
Or with some explicit dereferencing:
for (keys %conductordata){ my $ref = $conductordata{$_}; print OUT $ref->[0..1]; }
Which only returns the first and second item, to be safe.

Hope this helps,

Jeroen
"We are not alone"(FZ)

You can read more about it in perlref.

Apparently not what Gremlin wanted to know. Gremlin, what exactly is yer problem? Just the thing busunsl pointed out, probably....

I was asked for some deeper explanation for the hash overwrite. Well, It goes a bit deep. You'd probably want to read perldata on it. Perl differentiates between scalars, lists and hashes. So once you told the compiler a certain name (GLOB) represents a hash, it stays a hash. It even can coexist with a scalar by the same name!! (very confusing at first, but handy. It means you can say 'print $data for my $data (@data);'.)

Having said this, a call to %some_hash always represents the whole hash. If you want an element, use $some_hash{element}. In your code, you assign to the whole hash in %conductordata = ("conductor$i"=>....... This results in a complete fresh hash, with only one element, but that in each iteration of your loop!

All you have to do, is to assign to an one element each time. You only have the get the element before the '=': $conductordata{"conductor$i"} = [@elements].

Moreover, your data fit conceptually into either a nested hash or a two-dimensional array:

$number=$values{"number"}; my $con_data=[]; for ($i=1 ;$i<=$number ; $i++){ push @$con_data, [$values{"radius$i"}, $values{"length$i"}]; }
Clean this up a little bit:
my @numbers = grep{ s/radius(\d+)/$1/ } keys %values; $con_data[$i] = [$values{"radius$i"}, $values{"length$i"}] for my $i ( +@numbers); #then print: print OUT @$_ for (@$con_data);

In reply to Re: Printing Hash of Arrays by jeroenes
in thread Printing Hash of Arrays by Gremlin

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.