in reply to how to print out a variable name and its value

Yes - use Data::Dumper::Names:

use Data::Dumper::Names; my $foo = 3; my @bar = qw/this that/; warn Dumper($foo, \@bar); __END__ output: $foo = 3; @bar = ( 'this', 'that' );

Replies are listed 'Best First'.
Re^2: how to print out a variable name and its value
by perlfan99 (Sexton) on Jul 30, 2008 at 06:56 UTC
    thanks! i guess if i want to format the output differently, i need to read Dumper source code.
      Dumper can be controlled by some attributes, read the man pages first! I, personally, like Data::Dump::Streamer better:
      $ perl -e ' use Data::Dump::Streamer; my $firstname = "Edward"; my $var = 1; my @jack = ('a', '1', { b => 3, c => [1, 2]}); DumpLex($firstname, $var, \@jack)->Indent(0)->OptSpace(" ")->Out(); ' $firstname = 'Edward'; $var = 1; @jack = ( 'a', 1, { b => 3, c => [ 1, 2 ] } );
      Or, if the vars aren't lexical,
      $ perl -e ' use Data::Dump::Streamer; $firstname = "Edward"; $var = 1; @jack = ('a', '1', { b => 3, c => [1, 2]}); DumpVars(firstname => $firstname, var => $var, jack => \@jack)->Indent +(0)->OptSpace(" ")->Out(); ' $firstname = 'Edward'; $var = 1; $jack = [ 'a', 1, { b => 3, c => [ 1, 2 ] } ];
      []s, HTH, Massa (κς,πμ,πλ)
        Mucho gracias. Else, I would have not been interested in the D'D'Streamer for D'D has been good enough for me.

      Would

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

      -- 
      Ronald Fischer <ynnor@mm.st>
        no, it doesn't work. it prints out the variable value not its name