in reply to Problems with Hash Keys and Spaces

How are you defining $variable? I just ran your code with $variable set to "Another generic key" and received 4575 out. See code below:

my %hash = ( "Common SW Component" => "4885", "Test MMA" => "5130", "Generic key" => "5033", "Another generic key" => "4575", ); my $variable = "Another generic key"; print "$hash{$variable}\n";

Replies are listed 'Best First'.
Re^2: Problems with Hash Keys and Spaces
by Anonymous Monk on Aug 08, 2008 at 16:33 UTC
     my $variable = "$temp[1]";
      So, What's in $temp[1]?

      Add

      use Data::Dumper;

      Near the top of your program, and

      print Dumper \@temp;

      just before the line with the error


      Unless I state otherwise, all my code runs with strict and warnings
        I can post a small portion of it, only because it's for an internal project.
        $VAR1 = [ '', ', 'Test MMA '/dir/internal_stuff
        There are a few more dirs listed in the array, the 0 spot in the array is empty, 1 contains the info I need and the rest contain directories.
        $VAR1 = [ '', ', 'Test MMA '/dir/k_apps/
        In the array, slot 0 is empty, 1 has the info I want to be matched with the key, and the rest are all component directories. Thanks
      Don't interpolate "$temp[1]". You may be losing information due to interpolation. Try this instead:
      my $variable = $temp[1];