Regardless of tone, Abigail-II is correct. You should have based your object from Tie::Hash instead: (update: added DELETE)
package Tie::Hash::MultiVal; use strict; use warnings; use Tie::Hash; use base qw(Tie::StdHash); sub TIEHASH { my $class = shift; return bless {@_}, $class; } sub STORE { my ($hash,$k,$v) = @_; if (exists $hash->{$k}) { if (ref $hash->{$k}) { push @{$hash->{$k}}, $v; } else { $hash->{$k} = [$hash->{$k},$v]; } } else { $hash->{$k} = $v; } } sub DELETE { my ($hash,$k) = @_; if (ref $hash->{$k}) { pop @{$hash->{$k}}; $hash->{$k} = $hash->{$k}[0] if @{$hash->{$k}} == 1; } else { delete $hash->{$k}; } } 1;
Now i can use this to solve the 'problem' i had over at URI.pm bug or am i missing something? ... notice the slice ;)
use strict; use warnings; use URI; use Data::Dumper; use Tie::Hash::MultiVal; my $uri = URI->new('http://foo.com/bar.cgi?foo=bar&foo=baz&bar=qux&baz +=qux'); my %hash; tie %hash, 'MyHash'; %hash = $uri->query_form(); @hash{qw(foo bar baz qux)} = qw(one two three four); delete $hash{foo}; print Dumper \%hash;

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to (jeffa) Re: Unconstructive Criticism by jeffa
in thread Object to Map Multiple Values to a Single Key by arunhorne

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.