in reply to Re^2: how to print out a variable name and its value
in thread how to print out a variable name and its value

Would

# Warning! Code not tested! $_=eval($name); print(defined $_ ? ("$name=[$_]") : "$name is undefined");
do the trick?

-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re^4: how to print out a variable name and its value
by perlfan99 (Sexton) on Jul 30, 2008 at 07:30 UTC
    no, it doesn't work. it prints out the variable value not its name

      Hmmmm.... For me it works. Here a complete program to demonstrate the concept:

      use strict; use warnings; my $var1=35; my $var2=undef; foreach my $name ('$var1','$var2') { $_=eval($name); print(defined $_ ? ("$name=[$_]") : "$name is undefined","\n"); }
      This prints:
      $var1=[35] $var2 is undefined

      -- 
      Ronald Fischer <ynnor@mm.st>