Variables can help you clarify what you code does. Something an obscure data structure does not. For example,
my $DEBUG = 1;
#... later in your code
if ($DEBUG) { warn "Something happened\n" }
I bet your thinking that this is pretty obvious but I still want to reduce the number of variables.
If you think you have too many variables in a section of code, chances are you have not abstracted out it out enough. Move more of your code into other subroutines to enhance clarity.
my $dimensions = _get_dimensions_for(5,8);
while (my ($r,$s) = each %{ $dimensions } ) {
print($r);
}
sub _get_dimensions_for {
my $x = shift;
my $y = shift;
return {
x=> $x,
y=> $y
}
}
Note: Thanks to ikegami for pointing out my error.