Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Cannot write data struct to %ENV

by Discipulus (Canon)
on Jun 11, 2015 at 09:25 UTC ( [id://1129996]=note: print w/replies, xml ) Need Help??


in reply to Cannot write data struct to %ENV

%ENV is meant to expose ENV to Perl. In ENV You just cannot have datastructures, only strings. Even if you can add a datastructure to the Perl %ENV hash i think is not a reliable behaviour. %ENV has also a lot of magic underlying: think about case of the keys.
perl -MData::Dumper -e "$ENV{MyExtraConfig} = { foo=>{Bar => 'Blaz'}}; +print Dumper (\%ENV);system qq(set)"

UPDATE: in the docs is said "As of v5.18.0, both keys and values stored in %ENV are stringified."
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.

Replies are listed 'Best First'.
Re^2: Cannot write data struct to %ENV
by Corion (Patriarch) on Jun 11, 2015 at 09:30 UTC

    Cool that you even found the relevant documentation. As I've been playing with magic recently, I think it shouldn't be too hard to make %ENV warn if you try to store a reference to it. Of course, this adds another warning, and people who use fatal warnings might break their program, but it was broken beforehand.

Re^2: Cannot write data struct to %ENV
by exilepanda (Friar) on Jun 11, 2015 at 09:47 UTC
    Thank you very much!! Now the puzzle is solved and lesson learned. Could you elaborate more about why this is not reliable though?
      If the behaviour change between version of Perl, it is unreliable. In the ENV (of your OS) values will always be stringyfied, older Perl version had permit you to add datastructure to %ENV, but this is not logic as Env will contain only strings. So the behaviour was corrected.
      See also Environment and wikipedia too.

      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://1129996]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found