Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: How can I convert this raw data to a hash?

by afoken (Chancellor)
on Dec 23, 2020 at 11:33 UTC ( [id://11125674]=note: print w/replies, xml ) Need Help??


in reply to Re: How can I convert this raw data to a hash?
in thread How can I convert this raw data to a hash?

If you replace : with => (or even a comma), then you'd have PON - Perl Object Notation, also known as actual Perl code. So having that you could then do something silly like prepend our $hash_ref = then string eval or write it to a file then require it:

And if - for some nasty reason - the input suddenly contains something like "foo" : `rm -rf /` ("foo" => `rm -rf /` after replacing : with =>), you will learn the hard way why you don't blindly run configuration data as executable code. JSON, JSON::PP, and JSON::XS all treat data as such and do not treat the input as executable code. Hell, you don't even eval() JSON in Javascript - for the same reason.

See also:

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Replies are listed 'Best First'.
Re^3: How can I convert this raw data to a hash?
by perlfan (Vicar) on Dec 23, 2020 at 19:38 UTC
    To be fair, accepting rando Storable input files has thia caveat. My only point that it was very close to defining a hash ref.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-04-25 22:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found