Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

A Quote

by arunhorne (Pilgrim)
on May 27, 2003 at 13:57 UTC ( [id://260990]=note: print w/replies, xml ) Need Help??


in reply to Re: Object to Map Multiple Values to a Single Key
in thread Object to Map Multiple Values to a Single Key

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
(jeffa) Re: Unconstructive Criticism
by jeffa (Bishop) on May 27, 2003 at 14:30 UTC
    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)
    
Re: Unconstructive Criticism
by adrianh (Chancellor) on May 27, 2003 at 15:09 UTC
    The object was never meant to be a replacement for hashes

    That was (as I read it) Abigail's point. You're not providing a front end to a hash, you're providing an easy way of doing key -> arrayref mappings. You're dealing with a hashref not a hash. Hence your module description could be better expressed.

    I think you read way to much into Abigail's post. Abigail's (usually pretty darn accurate) comments may be blunt, but the bluntness is always aimed at code, not people.

    Unlike your message, which I --'d since I find it too close to a personal attack for my tastes.

    The object is trivial. Nothing wrong with that in itself. However we have an expressive syntax in Perl already for this sort of thing.

    my %map; push @{$map{K1}}, 'V1'; push @{$map{K1}}, 'V2'; push @{$map{K2}}, 'V3'; push @{$map{K3}}, 'V4'; print Dumper(\%map); # or my %map2; $map2{K1} = ['V1', 'V2']; $map2{K2} = ['V3']; $map2{K3} = ['V4']; print Dumper(\%map2); # or my %map3; @map3{'K1','K2','K3'} = (['V1', 'V2'], ['V3'], ['V4']); print Dumper(\%map3); # etc.

    So, for me, it doesn't really supply anything that Perl doesn't give us already for free.

    On a stylistic note I would use add_value() (or similar) rather than put() since the latter sounds like it should be the inverse of get() and it isn't.

Re: Unconstructive Criticism
by Jenda (Abbot) on May 28, 2003 at 14:21 UTC

    RTFM is quite often the best response we can give. Assuming we include which TFM and where to find it. If TFM contains the answer why should we waste time to write it again? Or copy it from the docs? If you get the pointer to the docs you will read the answer there and know where to look next time.

    Of course if you say you do not get the answer from the docs it's something completely different. In that case we should try and give you a different explanation ... or point you to some other FM.

    <sigh>To tell the truth the hardest questions to respond to are those that show the complete ignorance on the other party. Not those that show that the person did not care to look for the answer in any docs, but those that show he/she doesn't have any idea whay is he/she doing. Those that show that the person speaks a different language (no, I don't mean uninteligible translations from his/her mother language to English), that there is so huge a gap between his/her way of thinking and yours that there is simply no way to pass any information. In that case I really don't know what FM to suggest. Sometimes I think the person should start with Math for the second grade. (No that's not your case.)<sigh>

    Jenda
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
       -- Rick Osborne

    Edit by castaway: Closed small tag in signature

Re: Unconstructive Criticism
by Anonymous Monk on May 27, 2003 at 17:25 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://260990]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-18 18:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found