in reply to Re: replace text using hash
in thread replace text using hash

Hi,

Thank you for your replies. I have done it but the output is:

This is a ARRAY(0xe5d6c0)

Thanks

Replies are listed 'Best First'.
Re^3: replace text using hash
by LanX (Saint) on Sep 09, 2014 at 13:57 UTC
    See update of my first reply.

    The whole push is nonsense.

    Cheers Rolf

    (addicted to the Perl Programming Language and ☆☆☆☆ :)

      So, what can I do in that case?

        while (<DIC>) { my ( $key, $tgt ) = split(/\t/, $_); push @{ $dictionary{$key} }, $tgt; }
        Puts an array reference in each hash value, not the scalar value as you intend. You should only be doing this if you require a one-to-many mapping, which makes no sense in this context. What you actually want is to just assign the value:
        while (<DIC>) { my ( $key, $tgt ) = split(/\t/, $_); $dictionary{$key} = $tgt; }

        #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

        This is not a code writing service for homework tasks.

        Cheers Rolf

        (addicted to the Perl Programming Language and ☆☆☆☆ :)