in reply to variable with $$
See dominus' classic 3 articles on his website, for more arguments against it:
In general: don't do it. Use a hash. Like this:
my %v; # my hash for user variables $v{Sam}++; # or: my $name = 'Sam'; $v{$name}++;
Oh, and if you really want to do it, try $$name or ${$name}, which both do the same thing, and only work on global (= package) variables — and only with no strict 'refs'. Just to show you it can be done... ;-)
If all you want is to work on predefined variables with no input from the user/outside world, try hard references instead.
Yes, the syntax is exactly the same. That's one reason why coding without strict 'refs' in place, is a rather bad idea.my $var = \$sam; $$var++; # increments $sam
|
---|