I can see some vague utility if you want to access global variables. In this case, you can use a plain hash to get a quick hack that works even with strict and warnings turned on:
If you want to go the dark-side way (but remember that it's difficult to get back!), you have to indirect the variable name you're building:#!/usr/bin/perl use strict; # Use good practices use warnings; my %globals = (barbaz => "something here"); foo("bar", "baz"); sub foo { my $name = join('', @_); # Build varname print $globals{$name}, "\n"; # use it at will.... }
But, at the risk of repeating myself and Fletch, you don't want to do that.#!/usr/bin/perl $barbaz = "something here"; foo("bar", "baz"); sub foo { $name = join('', @_); # Build varname print $$name, "\n"; # use it AT YOUR RISK! }
Flavio (perl -e 'print(scalar(reverse("\nti.xittelop\@oivalf")))')
Don't fool yourself.In reply to Re: Dynamically Building Variable Names
by polettix
in thread Dynamically Building Variable Names
by willyyam
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |