I want the order of the keys while printing to be the same as when the keys were read in!
Tie::IxHash will do this for you.
Any tips please!
Yes, I have some more tips...

Use the strictures to find other potential problems with your code:

use warnings; use strict;

This would produce the following warnings:

Scalar value @ARGV[0] better written as $ARGV[0] at ... Scalar value @temparray[0] better written as $temparray[0] at ...
It will then be necessary to declare all variables with my to get the code to compile again.

Always check success when you open a file, and always close the file.

I refactored your code:

#!/usr/bin/env perl use warnings; use strict; use Tie::IxHash; tie my %goldhash, "Tie::IxHash"; my $goldcsv = shift; my @keyarray; my @temparray; open my $GOLD_FH, '<', $goldcsv or die "Can not open $goldcsv $!\n"; my $i = 0; while (<$GOLD_FH>) { chomp; $i++; if ($i eq 1) { @temparray = split /,/; my $j=0; for my $elem (@temparray) { $j++; next if ($j eq 1); push @keyarray, $elem; } next; } @temparray = split /,/; my $testcasename = $temparray[0]; for my $value (1 .. $#temparray) { $goldhash{$testcasename}{$keyarray[$value-1]} = $temparray[$va +lue]; } } close $GOLD_FH or die "Can not close $goldcsv $!\n"; for my $testcase (keys %goldhash) { print "$testcase: "; for my $value (keys %{ $goldhash{$testcase} }) { print "$value = $goldhash{$testcase}{$value} "; } print "\n"; }

Here is the output. Is this what you had in mind?

Test1: Stage1Mem = 44 Stage2Time = 45 Stage2Mem = 43 Stage1Time = +45 Test2: Stage1Mem = 7 Stage2Time = 34 Stage2Mem = 45 Stage1Time = 2 +334

In reply to Re^2: CSV file reading and comparison by toolic
in thread CSV file reading and comparison by tsk1979

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.