in reply to Hash key/value

What exactly do you mean by "not recognized"? Seems to work fine:

#!/usr/bin/perl $something{'that\'s it'} = "foo"; $something{'thats it\!'} = "bar"; use Data::Dumper; print Dumper \%something; __END__ $VAR1 = { 'that\'s it' => 'foo', 'thats it\\!' => 'bar' };

Replies are listed 'Best First'.
Re^2: Hash key/value
by FireBird34 (Pilgrim) on Nov 26, 2009 at 19:27 UTC
    My apologies, was in a rush when I wrote that.

    I have a file foo.txt that contains a phrase such as "that's it!". I read the contents of the file, and use the filename (foo) as the value in a hash, with the key being the contents:
    $key = "that's it!"; #contents from file foo.txt $value = "foo"; #filename $something{$key} = $value; print $something{$key};
    When I try to print the above, nothing is there, however when I remove the ' and !, "foo" is printed. I will play with the suggestions in a short while however. Might realize it's just how I'm doing it. Thank you for the quick replies.

      Maybe you should write some code that fails as you describe? Adding strictures (use strict; use warnings;) to your code and running it I get:

      use strict; use warnings; my %something; my $key = "that's it!"; #contents from file foo.txt my $value = "foo"; #filename $something{$key} = $value; print $something{$key};

      which prints:

      foo

      just as I would expect. Can you show me equivelent code that fails?


      True laziness is hard work
      FireBird34: Your subsequent post indicates your problem is resolved, but just for the record:
      >perl -wMstrict -le "my $key = \"that's it!\"; my $value = \"foo\"; my %something; $something{$key} = $value; print $something{$key}; use Data::Dumper; print Dumper \%something; " foo $VAR1 = { 'that\'s it!' => 'foo' };