in reply to formatted hash problem

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

Replies are listed 'Best First'.
Re^2: formatted hash problem
by AnomalousMonk (Archbishop) on Feb 05, 2010 at 19:41 UTC
    ... not sure how Perl would handle an exponential value...

    Further to kennethk's post: In almost as many characters as are quoted above, Spooky could have actually seen how Perl handles an exponential value. Sorry if the following rather pounds this into the ground:

    >perl -wMstrict -le "print 3.34e-10; print '3.34e-10'; print 1 + '3.34e-10'; printf qq{%15.15e \n}, 3.34e-10; print 'etc...'; " 3.34e-010 3.34e-10 1.000000000334 3.340000000000000e-010 etc...
Re^2: formatted hash problem
by Spooky (Beadle) on Feb 05, 2010 at 15:48 UTC
    Kenneth, I printed off "How (Not) To Ask A Question" and "Writeup Formatting Tips" (quite a few pages!). I'll also try your code and get back to you. It may be next week as we're expecting quite a snow storm and I'll be leaving a little early. Thanks again!
      There are plenty of printed documents on my desk that I could care less about. Read "How (Not) To Ask A Question" and meditate upon what it says - this is a monastery of sorts after all. Remember that this is a free service where people much more experienced in Perl than you or I offer their (literally) valuable advice and insight out of the kindness of their hearts. Before you ask your neighbor for help with a home improvement project, would you not contemplate the best way to implement it and probably do some basic ground work like clearing space? It sounds like you are getting dangerously close to being considered a bad neighbor, which does not bode well for when down the line you encounter more Perl challenges.
Re^2: formatted hash problem
by Spooky (Beadle) on Feb 19, 2010 at 17:27 UTC
    Kenneth, ..for some reason, for some relays the seconds field is blank. I'd like to delete that entry but not sure the best way to do this using your code above which works very well.
      Again, your question asking skills are leaving something to be desired. I don't know what the "seconds" field is. Copy the code above, put some data that does the wrong thing into the data block, and then tell us what the right thing would be.

      One possibility if a field is not getting populated is related to my split expression. My regular expression /\s/ splits on exactly one white space character. If your data has multiple spaces separating two values, you will get empty elements. /\s+/ will match one-or-more white space characters (perlre) and may fix this.

        ..yep, the "+" after the "s" did the trick. Incidentally, how should I have responded?