in reply to Re: why aren't I see the hash while using dump?
in thread why aren't I see the hash while using dump?

grrr, I see what you did! thanks! it wasn't dump...still figuring this out. thanks again. can I use "push" to get keys and values?
  • Comment on Re^2: why aren't I see the hash while using dump?

Replies are listed 'Best First'.
Re^3: why aren't I see the hash while using dump?
by FreeBeerReekingMonk (Deacon) on Jun 01, 2015 at 22:18 UTC

    You _can_ typecast, however, like so (array to hash key value pairs)

    use Data::Dumper; use warnings; use strict; open FOO, "test_data.txt" or die $!; my @A; while(<FOO>){ chomp; push @A, split /\s*=\s*/, $_, 2 } my %H = @A; print Dumper(\%H);

    Included a maximum of 2 elements in the split, as suggested by An.Monk.

      You can, and it's a good thing to know sometimes, but in this case it'll cause strange things to happen if there's more than one = on a line. Your original suggestion was better, perhaps with the enhancement of giving the split a limit, e.g. split /\s*=\s*/, $_, 2.

Re^3: why aren't I see the hash while using dump?
by FreeBeerReekingMonk (Deacon) on Jun 01, 2015 at 21:59 UTC

    push/pop and shift/unshift are for arrays only, not hashes.