Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Need to get hash of arrays -- oneliner

by Discipulus (Abbot)
on May 14, 2021 at 09:46 UTC ( #11132571=note: print w/replies, xml ) Need Help??


in reply to Need to get hash of arrays

As you are collecting solutions.. and dealing with highly malformed data..

perl -MData::Dump -F"\|\s?" -lane "$.==1?next:push@{$h{eval$F[0]=~tr/\ +s//r}},$F[1]}{dd%h" columndata.txt ( 500002, ["Network2"], 500003, ["Network1", "Network3"], 500001, ["Network1", "Network2"], )

which deparsed gives:

perl -MO=Deparse -MData::Dump -F"\|\s?" -lane "$.==1?next:push@{$h{eva +l$F[0]=~tr/\s//r}},$F[1]}{dd%h" columndata.txt BEGIN { $/ = "\n"; $\ = "\n"; } use Data::Dump; LINE: while (defined($_ = readline ARGV)) { chomp $_; our @F = split(/\|\s?/, $_, 0); $. == 1 ? next : push(@{$h{eval $F[0] =~ tr/s//r};}, $F[1]); } { dd(%h); } -e syntax OK

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (1)
As of 2021-09-26 13:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?