Phoenix.pm: Getting a name of a variable.
Scott Wessels
swessels at usgn.net
Thu Sep 13 20:10:43 CDT 2001
here's a possibility:
{
my @file_contents; # cache file contents
sub printHash(%) {
my %hash = @_;
unless (@file_contents) {
open SELF, $0;
@file_contents = <SELF>;
close SELF;
}
print 'Contents of ',
($file_contents[(caller)[2] - 1] =~ m/printHash.*?%(\w+)/)[0],
":\n",
map ({ qq{ $_\t => '$hash{$_}'\n} } keys %hash),
"\n";
}
}
my %testHash = (test => 1, again => 'alpha');
printHash %testHash;
modification may be necessary for finding the line that the call was made
from
----- Original Message -----
From: Erik Tank <erik.tank at bpxinternet.com>
To: <phoenix-pm-list at happyfunball.pm.org>
Sent: Thursday, September 13, 2001 1:40 PM
Subject: Phoenix.pm: Getting a name of a variable.
> I have a debugging module that I have been working on. One of the methods
> prints out the contents of a hash that is passed to it. I think that it
> would be cool to have the name of the hash appear above the output. Does
> anyone know how to take a variable an get it's name?
>
> Thanks,
>
> Erik Tank
> 602-817-4705
> erik.tank at bpxinternet.com
>
>
More information about the Phoenix-pm
mailing list