in reply to Assign and print Hash of hashes

Rather than reading all your data into an array and then subsequently processing it, I'd suggest just reading it from the file and processing it line-by-line:

open my $fh, '<', 'sample.data' or die $!; while (<$fh>) { # chomp # split # assign to hash } close $fh;

Note I've suggested chomp - this will remove newlines which are probably might end up in your hash values after recoding. You haven't shown an example of your input so that's a guess.

Update: The paragraph about chomp was badly phrased - I've reworded it.

-- Ken

Replies are listed 'Best First'.
Re^2: Assign and print Hash of hashes
by jwkrahn (Abbot) on Nov 22, 2010 at 08:30 UTC
    this will remove newlines which are probably in your hash values

    sundeep is using split /\s+/,$file[$i]; which will remove ALL whitespace so there definitely will not be any newlines in the keys or values.

      Thanks for pointing that out. I've reworded the sentence.

      -- Ken