in reply to multi level hash terror - if statement to access specific elements

 $names{$key}{$key2}[0] = 'Gay'

= is the assignment operator

eq is the string equality operator

See http://perldoc.perl.org/perlintro.html#String-comparison and http://perldoc.perl.org/perlop.html#Equality-Operators

  • Comment on Re: multi level hash terror - if statement to access specific elements
  • Download Code

Replies are listed 'Best First'.
Re^2: multi level hash terror - if statement to access specific elements
by hungrysumo79 (Initiate) on Feb 13, 2016 at 02:29 UTC
    Thanks but that still prints out the entire hash instead of just the last name of "Gay"

      Thanks but that still prints out the entire hash instead of just the last name of "Gay"

      So you want to fix this?

      for my $key ( keys %names ) { for my $key2 ( keys $names{$key} ) { print "First Name:" . $names{$key}{$key2}[0], "\n"; if ( $names{$key}{$key2}[0] = 'Gay' ) { print "Last Name:" . $names{$key}{$key2}[1] . "\n"; } } }

      You want to only print when last name is Gay?

      Its simple, get rid of the other print statement

        Removing the print doesn't help - it is printing every last name in the database table. I just want it to print the surname of 'Gay' when it finds the first name 'Gay'. Only surnames should be printed whose first name is 'Gay' It seems to be printing every surname in the table.

        for my $key (keys %names){ for my $key2(keys $names{$key}){ if ($names{$key}{$key2}[0] = 'Gay'){ print "Last Name:".$names{$key}{$key2}[1]."\n"; } } }
        Thanks for the help here :)