Skip Menu |

This queue is for tickets about the Tie-Hash-MultiValue CPAN distribution.

Report information
The Basics
Id: 35532
Status: resolved
Worked: 6 hours (360 min)
Priority: 0/
Queue: Tie-Hash-MultiValue

People
Owner: mcmahon [...] cpan.org
Requestors: d.t.rajan [...] ieee.org
Cc:
AdminCc:

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



CC: "Joe McMahon" <mcmahon [...] ibiblio.org>
Subject: Re: Tie::Hash::MultiValue question
Date: Tue, 29 Apr 2008 15:58:41 -0700
To: bug-Tie-Hash-MultiValue [...] rt.cpan.org
From: Darin <d.t.rajan [...] ieee.org>
Printing 'value' results in the array reference being printed. On Wed, Apr 16, 2008 at 9:42 AM, Darin <d.t.rajan@ieee.org> wrote: Show quoted text
> Cool- Thank you! > > -Darin > > > > On Tue, Apr 15, 2008 at 7:07 PM, Joe McMahon <mcmahon@ibiblio.org> wrote:
> > > > On Apr 15, 2008, at 9:44 AM, Darin wrote: > >
> > > I am using it of course to store multiple values per key. I would like > > > to know how I can iterate over the hash to print out the key, value > > > pairs, as in this example: > > > > > > tie %hash, 'Tie::Hash::MultiValue'; > > > > > > ... > > > > > > while ( ($key, $value) = each %hash){ > > > print "$key => $value\n"; > > > } > > > > > > Doing this results in printing of the array reference for key and > > > nothing for value. > > >
> > > > This sound like it might be a bug - I'll look into it. > > > > --- Joe M. > >
>
Subject: Re: [rt.cpan.org #35532] Re: Tie::Hash::MultiValue question
Date: Tue, 29 Apr 2008 16:26:51 -0700
To: bug-Tie-Hash-MultiValue [...] rt.cpan.org
From: Joe McMahon <mcmahon [...] yahoo-inc.com>
On Apr 29, 2008, at 3:59 PM, Darin via RT wrote: Show quoted text
> > Tue Apr 29 18:59:10 2008: Request 35532 was acted upon. > Transaction: Ticket created by d.t.rajan@ieee.org > Queue: Tie-Hash-MultiValue > Subject: Re: Tie::Hash::MultiValue question > Broken in: (no value) > Severity: (no value) > Owner: Nobody > Requestors: d.t.rajan@ieee.org > Status: new > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=35532 > > > > Printing 'value' results in the array reference being printed.
My apologies for not addressing this sooner, but day-to-day stuff has taken priority for the moment. I think this should be a relatively simple thing to patch (the Tie::Hash implementation of each(), obviously), but it will have to wait until more time frees up. --- Joe M.
Subject: Re: [rt.cpan.org #35532] Re: Tie::Hash::MultiValue question
Date: Thu, 1 May 2008 11:37:11 -0700
To: bug-Tie-Hash-MultiValue [...] rt.cpan.org
From: Darin <d.t.rajan [...] ieee.org>
No worries - I too haven't had time to dig in to src for Tie::Hash::MultiValue. Opened this ticket as a place holder for the bug. On Tue, Apr 29, 2008 at 4:27 PM, mcmahon@yahoo-inc.com via RT <bug-Tie-Hash-MultiValue@rt.cpan.org> wrote: Show quoted text
> > <URL: http://rt.cpan.org/Ticket/Display.html?id=35532 > > > > On Apr 29, 2008, at 3:59 PM, Darin via RT wrote: >
> > > > Tue Apr 29 18:59:10 2008: Request 35532 was acted upon. > > Transaction: Ticket created by d.t.rajan@ieee.org > > Queue: Tie-Hash-MultiValue > > Subject: Re: Tie::Hash::MultiValue question > > Broken in: (no value) > > Severity: (no value) > > Owner: Nobody > > Requestors: d.t.rajan@ieee.org > > Status: new > > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=35532 >
>
> >
> > > > Printing 'value' results in the array reference being printed.
> > My apologies for not addressing this sooner, but day-to-day stuff has > taken priority for the moment. I think this should be a relatively > simple thing to patch (the Tie::Hash implementation of each(), > obviously), but it will have to wait until more time frees up. > > --- Joe M. > >
Okay: I have both a definitive answer and a new alternative API. When you've tied a hash, every call to FETCH occurs in scalar context. This makes sense, since hashes prototypically only store scalar values. However, this means this it just isn't possible at all to return an array directly from a hash fetch ( $hash{$key} ). You therefore have to choose one of two methods: - get an anonymous array back and iterate over it - have the tied class iterate over the stored values, returning them one at a time until you've seen them all. I've updated the most recent version of the code to add the built-in iterator option. The default is to be in 'refs' mode, which always returns a reference to the list of items in the hash entry. Putting the tied hash into 'iterators' mode lets you do the 'fetch values repeatedly until there are no more' version. It looks like the assumption that accessing a hash element always occurs in scalar context is wedged way down inside Perl; one might be able to patch around it, but I'm not sure it's worth doing that much work (and potentially introducing bugs in other stuff that assumes that context doesn't matter for hash fetches). So I'll upload 1.0 with the new 'iterators' stuff and close this as 'fixed', since there's not a "this is the best compromise we can make but doesn't really fix it" resolution. :)