Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: creating the hierarchy pattern from the input file

by LanX (Saint)
on Sep 16, 2021 at 10:47 UTC ( [id://11136822]=note: print w/replies, xml ) Need Help??


in reply to Re: creating the hierarchy pattern from the input file
in thread creating the hierarchy pattern from the input file

> P.S. This is also sure to upset the eval haters :)

Trouble is rather that you might end with a bug depending on input if you try increment a hashref.

I would prefer

DB<41> $ref= $tree DB<42> x @keys = split /@/,'a@b@c' 0 'a' 1 'b' 2 'c' DB<43> $ref = ($ref->{$_}//={})for @keys DB<44> x $tree 0 HASH(0xaa630cf0) 'a' => HASH(0xaa6204a0) 'b' => HASH(0xaa6719b0) 'c' => HASH(0xaa75baa0) empty hash DB<45>

Update
And so on for each line
DB<45> x @keys = split /@/,'a@b@d' 0 'a' 1 'b' 2 'd' DB<46> $ref= $tree <= ($ref->{$_}//={})for @keys DB<48> x $tree 0 HASH(0xaa630cf0) 'a' => HASH(0xaa6204a0) 'b' => HASH(0xaa6719b0) 'c' => HASH(0xaa75baa0) empty hash 'd' => HASH(0xaa672e30) empty hash DB<49>

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2024-04-23 09:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found