How do I do something like 'print Dumper $var' in Embperl - I did this:
[-
$var = (some hash) ;
use Data::Dumper
print Dumper $var
-]
and this
[+ Dumper $var +]
...but couldn't get any output.
Did you mean Embperl?
If you want to dump a variable with Data::Dumper, you need to pass its reference. In your case:
use Data::Dumper;
my %hashvar = (a => 1, b => 2);
print Dumper(\%hashvar);
or
use Data::Dumper;
my $hashref= {a => 1, b => 2};
print Dumper($hashref);
In the first case the variable is a hash so you must take its reference; in the second you have a reference to a hash and is therefore passed as-is to Data::Dumper
I usually use Data::Dumper's
Dump
method, which produces a string I can do anything I want with.HOWEVER, please remember that in EmbPerl, you need to be careful where you print:
To print to Apache's error log, print to STDERR:
To print to your web page, print to
OUT
handle, or use[+ +]
includes. If it's a debug print, I usually just stick it inside an HTML comment: