in reply to Re^2: help with user selected hash operations?
in thread help with user selected hash operations?
If you indent this block
if ($choice eq 'a'){ print "Enter a male name: "; chomp (my $name1 = ucfirst lc <STDIN>); } if (exists $son_father{$name1}) { print "Duplicate name -- try again!\n"; } else { print "Add a father: "; chomp (my $add_dad = ucfirst lc <STDIN>); $son_father{$name1} = {$add_dad}; next; }
correctly you can see it is 2 blocks not 1
if ($choice eq 'a'){ print "Enter a male name: "; chomp (my $name1 = ucfirst lc <STDIN>); } if (exists $son_father{$name1}) { print "Duplicate name -- try again!\n"; } else { print "Add a father: "; chomp (my $add_dad = ucfirst lc <STDIN>); $son_father{$name1} = {$add_dad}; next; }
What you want is probably
pojif ($choice eq 'a'){ print "Enter a male name: "; chomp (my $name = ucfirst lc <STDIN>); if (exists $son_father{$name}) { print "Duplicate name $name -- try again!\n"; } else { print "Add a father: "; chomp (my $add_dad = ucfirst lc <STDIN>); $son_father{$name} = $add_dad; print "$name added with father $add_dad\n"; } next; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: help with user selected hash operations?
by lunette (Acolyte) on Oct 30, 2017 at 19:05 UTC |