I'm new to Perl, and this thing has got me stuck for far too long...
I want to dump a readable representation of the object itself from inside a function (I'm trying to debug something, and I'm doing this by returning an array reference which the caller expects, but containing an object dump rather than human readable text as per normal) so in my package I have:
use Data::Dumper;
sub somefunctionName{
my $self = shift;
my $d = Dumper($self);
my @retval = ();
push(@retval, $d);
return \@retval;
}
This is giving me the error "Can't use string ("the literal object dump goes here") as a HASH ref while "strict refs" in use"
I can't for the life of me figure out a way to make the error go away, no matter how I mess with the backslashes, and what I've done above looks to me like exactly what every online tutorial does... But I'm obviously missing the point somewhere.
What am I doing wrong?
sub somefunctionName{ my $self = shift; return Dumper($self); }andmy @list = somefunctionName(\&somefunctionName);not do the job? The array-ness is more determined by the recipient (@listin my example) than in the sub itself.$self(that obviously cannot be used as a reference). Without more to go on, there really isn't anything left to do buy guess.$VAR1 = { stuff ... }. Your problem is like Chris said that you then try to use this value as a hash, when it is not a hash, with something like$foo->[0]{key}. Which gives the warning you mentioned,Can't use string .. as HASH ref ...