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

See update of my first reply.

The whole push is nonsense.

Cheers Rolf

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

Replies are listed 'Best First'.
Re^4: replace text using hash
by Anonymous Monk on Sep 09, 2014 at 14:12 UTC

    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 ☆☆☆☆ :)