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

no, it doesn't work. it prints out the variable value not its name
  • Comment on Re^4: how to print out a variable name and its value

Replies are listed 'Best First'.
Re^5: how to print out a variable name and its value
by rovf (Priest) on Jul 30, 2008 at 08:23 UTC

    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>