But the basic problem was the . in the .= in make blank. The .= appends something to the scalar, in this case, nothing! It didn't make it blank.#!/usr/bin/perl -w use Data::Dumper; $a1 = 1; $a2 = 2; $a3 = 3; $b1 = 4; $b2 = 5; $b3 = 6; $c1 = 7; $c2 = 8; $c3 = 9; %squares = (a1 => $a1, a2 => $a2, a3 => $a3, b1 => $b1, b2 => $b2, b3 +=> $b3, c1 => $c1, c2 => $c2, c3 => $c3); print "Remove which one? "; chomp ($response = <STDIN>); &make_blank(); print Dumper %squares; print "\n"; print %squares; # makes the moved piece blank sub make_blank() { foreach $key (keys %squares) { ($squares{$key} = "") if ($key eq $response); } }
Updated purely to correct typo: s/.+/.=/
Updated - also the sub make_blank is called before the prototype is seen, so you should add the & in front to stop the rror message appearing.
In reply to Re: Newbie question
by jdtoronto
in thread Can I empty a hash value?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |