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

Re: Platform Dependence observed in Perl - Hash keys have different format

by Eily (Monsignor)
on Mar 03, 2017 at 10:00 UTC ( [id://1183542]=note: print w/replies, xml ) Need Help??


in reply to Platform Dependence observed in Perl - Hash keys have different format

The hash keys (when printed using Data::Dumper) were displayed within double quotes when the code was ran on different machine. On my machine, the hash keys appear without double quotes.

There are two package variables in Data::Dumper that can modify this behaviour:

$Data::Dumper::Quotekeys or $OBJ->Quotekeys([NEWVAL]) Can be set to a boolean value to control whether hash keys are quoted. A defined false value will avoid quoting hash keys when it looks like a simple string. Default is 1, which will always enclose hash keys in quotes.
$Data::Dumper::Useqq or $OBJ->Useqq([NEWVAL]) When set, enables the use of double quotes for representing string values. Whitespace other than space will be represented as [\n\t\r], "unsafe" characters will be backslashed, and unprintable characters will be output as quoted octal integers. The default is 0.

You should check the other modules you use, maybe one of them changes those package variables without resetting them, propagating the changed behaviour everywhere. BTW, to limit the effect of those variables you can use local.

{ local $Data::Dumper::Quotekeys = 0; print Data::Dumper \%hash; # No quote keys sub_from_other_module(); # No quote keys in the calls to Data::Dumpe +r from the other module } print Data::Dumper \%hash; # Quote keys sub_from_other_module(); # Quote keys as well

The default behaviour is neither of the cases you have observed though (it's single quotes, not doubles, not none) so that's still surprising.

  • Comment on Re: Platform Dependence observed in Perl - Hash keys have different format
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-19 19:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found