B
bongo
Hi folks. Perl newbie here. Having a heck of a
time with something which probably isn't that hard...
When debugging code in progress, I often find myself
typing:
print "\$var1=$var1, \$var2=$var2 \n";
not a big deal, but when you do it all the time, it
would be nice to save some typing by putting it in a
subroutine, such as:
dbg_pr($var1,$var2);
Easy enough if I just wanted the values, but I want to
print both the variable names and the values, and I'd
like to get both from one string. If I pass $var1 or \$var1
I can get the value but not the variable name, and if I
pass "var1" I get the name but not the value
(as ${"var1"} isn't defined in the subroutine name space.)
It doesn't seem like I can pass a string and construct a
reference from it. Can I somehow stringify \${var1} to
get "var1" instead of SCALAR(Hhex address)?
Any help appreciated. It seems as if this has to be simple,
but the best I can currently do is pass both the string and
the reference, which is almost as redundant as just retyping
the whole print statement every time.
thanks,
--bongo
time with something which probably isn't that hard...
When debugging code in progress, I often find myself
typing:
print "\$var1=$var1, \$var2=$var2 \n";
not a big deal, but when you do it all the time, it
would be nice to save some typing by putting it in a
subroutine, such as:
dbg_pr($var1,$var2);
Easy enough if I just wanted the values, but I want to
print both the variable names and the values, and I'd
like to get both from one string. If I pass $var1 or \$var1
I can get the value but not the variable name, and if I
pass "var1" I get the name but not the value
(as ${"var1"} isn't defined in the subroutine name space.)
It doesn't seem like I can pass a string and construct a
reference from it. Can I somehow stringify \${var1} to
get "var1" instead of SCALAR(Hhex address)?
Any help appreciated. It seems as if this has to be simple,
but the best I can currently do is pass both the string and
the reference, which is almost as redundant as just retyping
the whole print statement every time.
thanks,
--bongo