Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi, monks of Perl!
I have a number of variables where I need the name for logging. The names are known a priori, and a nominal amount of munging needs to occur within a function.
Pseudo-code for what needs to happen is as follows:
#!/bin/env perl use strict; use warnings; my ($a, $b, $c); $a = $b = $c = 0; foreach my $v (qw/a b c/) { func($v); } sub func { my $v = shift; print "v = $v\n"; eval($v = $v * 2); # incorrect syntax }
I know the eval() statement above is wrong, but I can't get either the expression or block form working. I'm rather confused.
Any enlightenment you can pass on would be greatly appreciated!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: eval & variable names?
by ikegami (Patriarch) on Jan 21, 2012 at 00:27 UTC | |
by Anonymous Monk on Jan 21, 2012 at 00:36 UTC | |
|
Re: eval & variable names?
by CountZero (Bishop) on Jan 21, 2012 at 07:54 UTC | |
|
Re: eval & variable names?
by educated_foo (Vicar) on Jan 21, 2012 at 09:07 UTC | |
|
Re: eval & variable names?
by JavaFan (Canon) on Jan 21, 2012 at 11:25 UTC | |
|
Re: eval & variable names?
by ricDeez (Scribe) on Jan 21, 2012 at 01:33 UTC | |
by ricDeez (Scribe) on Jan 21, 2012 at 01:50 UTC |