in reply to How to retrieve the name of a variable ?
In addition to toolic's suggestions, you could try Smart::Comments. If you're feeling adventurous, you could even use symbolic references. In general, not a great habit to get into, but for some tasks like this, they're not so bad.
$ cat t.pl #!/usr/bin/perl # Prevent symbolic references, etc. in general use strict; use warnings; # Use our instead of my to ensure that the value is accessible our $boom = 'Kaboom!'; our $bam = 'Kerblam!'; + # Unfortunately, the call looks odd... say_var('boom'); say_var('bam'); sub say_var { # Turn off strict for now no strict; my $t = shift; print "\$$t = >$$t<\n"; } $ perl t.pl $boom = >Kaboom!< $bam = >Kerblam!<
.... somehow I feel that I'll be roasted for suggesting such a thing ....
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to retrieve the name of a variable ?
by mascip (Pilgrim) on Jul 19, 2012 at 00:15 UTC | |
by roboticus (Chancellor) on Jul 19, 2012 at 00:19 UTC | |
by DStaal (Chaplain) on Jul 19, 2012 at 14:55 UTC | |
by mascip (Pilgrim) on Jul 19, 2012 at 15:38 UTC | |
by clueless newbie (Curate) on Jul 20, 2012 at 11:12 UTC |