in reply to Accumulating data in a hash using map{split()}

Guys,
Thx for those.

Re: Grandfather: actually I'm already using the 3rd param because some values can have ':' in them, but I agree your solution looks a bit obscure/magical.

I think I'll go with merlyn, as it's basically just hash merging like %a = (%b, %c), except of course it's $rec instead of <DATA>, for anybody else who reads this thread.

Thx again
Chris

  • Comment on Re: Accumulating data in a hash using map{split()}

Replies are listed 'Best First'.
Re^2: Accumulating data in a hash using map{split()}
by GrandFather (Saint) on May 04, 2007 at 00:25 UTC

    Actually I'd consider Merlyn's variant even more magical, but an idiom well worth knowing.

    There is a tension here between "succinct" and "lucid" with the two line version being at the lucid end of the spectrum and either of the one line solutions being toward the succinct end.

    You may find:

    %hash = (%hash, split /:/, <DATA>, 2);

    a little less magical than the variant using map btw in a context where you are dealing with single lines.


    DWIM is Perl's answer to Gödel
Re^2: Accumulating data in a hash using map{split()}
by chrism01 (Friar) on May 03, 2007 at 23:41 UTC
    ... and btw, it's a small amt of data, so efficiency isn't an issue

    Chris