Skip Menu |

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

Report information
The Basics
Id: 20289
Status: resolved
Priority: 0/
Queue: Tie-Hash-MultiValue

People
Owner: mcmahon [...] cpan.org
Requestors: dnb [...] pobox.com
Cc:
AdminCc:

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



Subject: assigning multiple values at once fails
The documentation says that assigning multiple values at a time should work, i.e. : $hash{'more'} = ('fee','fie', 'foe', 'fum'); Unfortunately this only assigns the last element to the list: x \%hash 0 HASH(0x359970) 'more' => ARRAY(0x3599f4) 0 'fum'
On Tue Jul 04 23:20:59 2006, guest wrote: Show quoted text
> The documentation says that assigning multiple values at a time should > work, i.e. : > > $hash{'more'} = ('fee','fie', 'foe', 'fum'); > > Unfortunately this only assigns the last element to the list: > > x \%hash > 0 HASH(0x359970) > 'more' => ARRAY(0x3599f4) > 0 'fum'
You are correct; at the moment I don't see a (non-filter) way to emulate list assignment. I would suggest a 'foreach' instead: foreach my $item (qw(fee fie foe fum)) { $hash{more} = $item } Not as nice, but it's the best alternative that I can come up with that doesn't involve nasty stuff. I will fix the docs in the next release.
On Tue Jul 04 23:20:59 2006, guest wrote: Show quoted text
> The documentation says that assigning multiple values at a time should > work, i.e. : > > $hash{'more'} = ('fee','fie', 'foe', 'fum'); > > Unfortunately this only assigns the last element to the list: > > x \%hash > 0 HASH(0x359970) > 'more' => ARRAY(0x3599f4) > 0 'fum'
You are correct; at the moment I don't see a (non-filter) way to emulate list assignment. I would suggest a 'foreach' instead: foreach my $item (qw(fee fie foe fum)) { $hash{more} = $item } Not as nice, but it's the best alternative that I can come up with that doesn't involve nasty stuff. I will fix the docs in the next release.
On Tue Jul 04 23:20:59 2006, guest wrote: Show quoted text
> The documentation says that assigning multiple values at a time should > work, i.e. : > > $hash{'more'} = ('fee','fie', 'foe', 'fum'); > > Unfortunately this only assigns the last element to the list: > > x \%hash > 0 HASH(0x359970) > 'more' => ARRAY(0x3599f4) > 0 'fum'
You are correct; at the moment I don't see a (non-filter) way to emulate list assignment. I would suggest a 'foreach' instead: foreach my $item (qw(fee fie foe fum)) { $hash{more} = $item } Not as nice, but it's the best alternative that I can come up with that doesn't involve nasty stuff. I will fix the docs in the next release.
Docs have been updated with an example of how to add multiple values at once via map(). Sorry I wasn't able to supply a more transparent solution.