in reply to Re^2: How to get specific hash elements?
in thread How to get specific hash elements?

What's with all the white space at the end of your keys? That's going to cause problems: 'Fixed_name1     ' does not equal 'Fixed_name1'.

-derby

Replies are listed 'Best First'.
Re^4: How to get specific hash elements?
by talking_walnut (Initiate) on May 15, 2007 at 08:59 UTC
    I figured that alright and tried the code with all the spaces but it didn't make any difference. I'm pulling the data from a database that's why the white space is there. That's also how it's being assigned the undef value although I don't know why. Here's the structure of the code that's doing that:
    my %ret; if ( defined( $rv ) and @$rv ) { map { %{$ret{$$_{name}}->{$$_{project}}={$$_{result}}} +} @$rv; } return %ret;

    Update: I finally managed to get this working the way I wanted. Just thought I'd post how I did it in case it's useful to someone else in the future and wanted to say thanks to everyone that took the time to reply to me. Here's the approach I took:
    my ($value1, $value2); foreach (sort keys %hash) { foreach (sort keys %{$hash{$random_name}}) { foreach $k1 (sort keys %{$hash{$random_name}{$fixed_name1}}) { $value1 = $k1; } foreach $k2 (sort keys %{$hash{$random_name}{$fixed_name2}}) { $value2 = $k2; } etc. } } print "$value1\n";
    Worked a charm. My full version has some error checking in case one of the values didn't exist. Did this with some if defined before the foreach and an else { after.