Skip Menu |

This queue is for tickets about the Data-Dumper-Names CPAN distribution.

Report information
The Basics
Id: 18213
Status: resolved
Priority: 0/
Queue: Data-Dumper-Names

People
Owner: Nobody in particular
Requestors: demerphq [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: Borrowed and improved name detection code.
Hi Ovid, I wanted to let you know that I have taken your code and used it in Data::Dump::Streamer::DumpLex(). The function is currently undocumented, and unattributed to you (which will change next release, please accept my apology for that) but basically functions as your code does. I made some improvements to the code to avoid the problem of my @array; my $foo = \@array; warn Dumper( $foo, \@array ); DDS has slightly different requirements than DD, so for instance my code doesn't need to make a name for things it can't identify, thats done elsewhere in the DDS code, so leaving them undefined is fine. But I'm sure you can adapt this as is required: my $pad = peek_my(1); my %pad_vars; while (my ($var,$ref) = each %$pad) { $pad_vars{ refaddr $ref } = $var; } my @names; my $varcount = 1; foreach (@_) { my $name; INNER:foreach ( \$_, $_ ) { $name=$pad_vars{refaddr $_} and last INNER; } push @names, $name; } The problem in your code is that the way you did the _address() function you ignore the container sv when it holds a ref. You need to check to see if you know the sv first, and only when you don't know it check to see whether it holds a ref to something you know about. cheers, demerphq ps: Heh, you can even see the $varcount variable is an artifact from when I borrowed your code. :-)
Subject: Re: [rt.cpan.org #18213] AutoReply: Borrowed and improved name detection code.
Date: Sat, 18 Mar 2006 00:41:59 +0100
To: bug-Data-Dumper-Names [...] rt.cpan.org
From: demerphq <demerphq [...] gmail.com>
On 3/17/06, demerphq wrote: Show quoted text
> DDS has slightly different requirements than DD, so for instance my code > doesn't need to make a name for things it can't identify, thats done > elsewhere in the DDS code, so leaving them undefined is fine. But I'm > sure you can adapt this as is required: > > my $pad = peek_my(1); > my %pad_vars; > while (my ($var,$ref) = each %$pad) { > $pad_vars{ refaddr $ref } = $var; > } > my @names; > my $varcount = 1; > > foreach (@_) { > my $name; > INNER:foreach ( \$_, $_ ) { > $name=$pad_vars{refaddr $_} > and last INNER; > } > push @names, $name; > } > > The problem in your code is that the way you did the _address() function > you ignore the container sv when it holds a ref. You need to check to > see if you know the sv first, and only when you don't know it check to > see whether it holds a ref to something you know about.
Actually i hadnt noticed var_name() in PadWalker, which lets you simplify the code to my @names= map { PadWalker::var_name(1,\$_) || PadWalker::var_name(1,$_) } @_; Cheers mate, yves -- perl -Mre=debug -e "/just|another|perl|hacker/"
From: ovid [...] cpan.org
Hi Yves, I've just uploaded a new version of Data::Dumper::Names based on your feedback. However, I do see that I may have missed your latest feedback. I'll wait to see how this version works for folks before I do much more. Thanks for the info! I've added you to the Acknowledgements sections. Cheers, Ovid On Fri Mar 17 05:40:01 2006, guest wrote: Show quoted text
> Hi Ovid, > > I wanted to let you know that I have taken your code and used it in > Data::Dump::Streamer::DumpLex(). The function is currently undocumented, > and unattributed to you (which will change next release, please accept > my apology for that) but basically functions as your code does. > > I made some improvements to the code to avoid the problem of > > my @array; > my $foo = \@array; > warn Dumper( $foo, \@array ); > > DDS has slightly different requirements than DD, so for instance my code > doesn't need to make a name for things it can't identify, thats done > elsewhere in the DDS code, so leaving them undefined is fine. But I'm > sure you can adapt this as is required: > > my $pad = peek_my(1); > my %pad_vars; > while (my ($var,$ref) = each %$pad) { > $pad_vars{ refaddr $ref } = $var; > } > my @names; > my $varcount = 1; > > foreach (@_) { > my $name; > INNER:foreach ( \$_, $_ ) { > $name=$pad_vars{refaddr $_} > and last INNER; > } > push @names, $name; > } > > The problem in your code is that the way you did the _address() function > you ignore the container sv when it holds a ref. You need to check to > see if you know the sv first, and only when you don't know it check to > see whether it holds a ref to something you know about. > > cheers, > demerphq > ps: Heh, you can even see the $varcount variable is an artifact from > when I borrowed your code. :-) > >