getting {string} from \${string}

bongo_at_frii.com
Date: 01/28/05


Date: 28 Jan 2005 12:33:47 -0800

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



Relevant Pages

  • Re: Word 2008 after install of Mac OS X 10.5.2
    ... I started to write a letter in Word and after typing the string "0165XSF", ... which is a reference number in my text) and hitting "enter", ... I was not aware, that I was applying some command, I just entered my text, ...
    (microsoft.public.mac.office.word)
  • Re: getting {string} from ${string}
    ... > would be nice to save some typing by putting it in a ... > but the best I can currently do is pass both the string and ... > the reference, which is almost as redundant as just retyping ... the literal expression and the value. ...
    (comp.lang.perl.misc)
  • Re: SQL
    ... Just a naked string. ... also that in this case it is not the context which determines the types, ... I.e. it is dynamic typing, ... PHP is an example of a dynamically-typed language (and frankly it is ...
    (comp.object)
  • Re: SQL
    ... Just a naked string. ... also that in this case it is not the context which determines the types, ... I.e. it is dynamic typing, ... interesting than math libraries IMO. ...
    (comp.object)
  • Re: how to convert variable name to a string?
    ... convert a string to a variable name ... x = "VAR1", how to use x to manipulate the VAR1? ... will form a 100 character length string with VAR1 as the first four ... variables) to do this kind of thing in fortran. ...
    (comp.lang.fortran)