Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re^10: Storing/parsing perl data structure in/from a file

by Wilderness (Novice)
on Jun 13, 2013 at 22:52 UTC ( #1038854=note: print w/replies, xml ) Need Help??

in reply to Re^9: Storing/parsing perl data structure in/from a file
in thread Storing/parsing perl data structure in/from a file

Sorry to make it confusing but my intention is to be able to `do` a file with the information below and flag that key alpha->beta and later alpha->beta->gamma is defined twice. Duplicate keys can be at any level of the multi-level hash.
{ alpha => { beta => { gamma => theta, delta => lambda, }, beta => { gamma => zeta, }, }, },

Replies are listed 'Best First'.
Re^11: Storing/parsing perl data structure in/from a file
by LanX (Chancellor) on Jun 13, 2013 at 23:22 UTC
    No this is your approach, you should explain your intention to use such a weird approach.

    I'm sure we can help you, if we just knew why ... this smell like an XY Problem! =)

    Your dump isn't even valid Perl code (barewords as values)!

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      Sorry to have completed pissed you off. It's ironical that I know it is an XY problem, yet I do not know what X and Y are...Anyways, after looking at all the responses, I wanted to know more about tying hashes and being able to override methods like STORE, FETCH, etc. to make them work for my multi-dimensional hash. But I haven't used OO-Perl before so I am struggling to write my own recursive methods to make it work for multi-level structures. I will go with YAML. It looks a lot more elegant than perl hashes in a file.
        You didn't piss me off, it's just not easy to speculate about fictional use cases!

        The tied hash doesn't work with nested literal hashes, they are cleaned at compile phase.

        Though you can use nested literal arrays like demonstrated w/o information loss.

        Assign them to a tied array, which STOREs them internally in a tied hash.

        Or just a normal array which is parsed afterwards!

        And yes YAML looks better! =)

        Cheers Rolf

        ( addicted to the Perl Programming Language)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1038854]
[ambrus]: And I don't much like syntax highlighters. If you need a syntax highlighter to understand your code, then your code is written unclear.
[ambrus]: And if you need a syntax highlighter to color parenthesis green and numbers black and letters blue, then you're using the wrong font.
[ambrus]: I have to tolerate syntax highlighters when other people use them, but I don't use them myself. And sorry for the rant.
[GotToBTru]: I appreciate the ability to highlight matching brackets/ parentheses/ braces, both for my own code and the inconsistently indented code of others
[Corion]: I like editors that automatically highlight the matching parenthesis (like % in vi), but that's roughly the extent to which I like editor support ;)
[GotToBTru]: same here Corion.
[Corion]: I tried for a short time (well, 8 hours now) to get Perl::Tidy set up but then found that it doesn't support (new-style) signatures and then stopped again ;))

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (12)
As of 2017-02-27 12:47 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (385 votes). Check out past polls.