What have you tried? Why has it not worked? See How (Not) To Ask A Question. As this is connected to previous threads (I assume a use for hashes?), you should reference them so other monks can follow and assist. You also should not put an entire post in <code> tags - it makes exposition more difficult to read. See Writeup Formatting Tips.

I do not entirely follow how your input maps to your output, even after reading the previous thread. Based upon my best guess, you should use a hash of arrays of arrays - see perllol for info on more advanced data structures. Note that while Perl would handle the scientific notation value with no difficulty, it doesn't matter since you are not doing math with it. As far as Perl is concerned, this is just a series of space-delimited strings. Does this do what you intend?

#!/usr/bin/perl use strict; use warnings; my %relays; while (<DATA>) { chomp; my @result = split /\s/; my $id = shift @result; for my $i (0 .. $#result) { push @{$relays{$id}[$i]}, $result[$i]; } } for my $id (keys %relays) { for my $field_ref ($relays{$id}) { for my $values_ref (@$field_ref) { print "$id @$values_ref\n"; } } } __DATA__ relay01 238 933 set relay02 238 934 9876536 2345.56 relay01 238 934 reset relay02 239 935 876555 23456.88 relay01 239 999 initiate relay03 240 877 899998 87698 relay03 241 888 98989898 3.34e-10

In reply to Re: formatted hash problem by kennethk
in thread formatted hash problem by Spooky

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.