in reply to Hash of Arrays

Why do you want to create arrays with just one value? The following code will do it...

my %hashofarrays=map{ my($key,$value)=split/[:]{2}=/; ($key=>[$value]) }<STDIN>;

However, I really question whether that's actually what you want. With only one value in the array, I don't see much sense in having the array. Wouldn't it be easier just to store the value directly in the hash? Or did you want to further split the value in some way, or push it onto the array so as to preserve possible previous values (update: as pg's answer guesses), or some other thing you aren't telling us about that would impact our answer? Knowing only what you've told us, the above code does what you asked, but I'm not confident it's right.


$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/

Replies are listed 'Best First'.
Re: Re: Hash of Arrays
by davido (Cardinal) on Oct 12, 2003 at 19:40 UTC
    My method doesn't store the value directly in the hash. It pushes it onto the anonymous array referenced by the value of the appropriate hash element.


    Dave


    "If I had my life to do over again, I'd be a plumber." -- Albert Einstein

      Umm, quite so. I misread your code. Sorry about that.


      $;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/