in reply to Re: Hash key/value
in thread Hash key/value

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.

Replies are listed 'Best First'.
Re^3: Hash key/value
by GrandFather (Saint) on Nov 26, 2009 at 20:57 UTC

    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
Re^3: Hash key/value
by AnomalousMonk (Archbishop) on Nov 26, 2009 at 21:00 UTC
    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' };