develooper Front page | perl.perl5.porters | Postings from October 2013

[perl #120384] Data::Dumper misbehaving on integer hash keys wrt useqq and quotekeys

From:
perlbug-followup
Date:
October 27, 2013 20:17
Subject:
[perl #120384] Data::Dumper misbehaving on integer hash keys wrt useqq and quotekeys
Message ID:
rt-4.0.18-13587-1382905022-1913.120384-75-0@perl.org
# New Ticket Created by  (Andreas J. Koenig) 
# Please include the string:  [perl #120384]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=120384 >


While analyzing some surprising results of some of my smokers together
with Marc Lehmann we discovered the following misbehaviour of current
bleadperl's Data::Dumper 2.149. The result does not look like a
regression, under 2.145 the behaviour was different but rather more than
less buggy.

The following program generates a table that shows that

(1) if useperl=0 and quotekeys=0, then integer hash keys are quoted

(2) if useperl=1, then integer hash keys are never quoted, ignoring
    the value of quotekeys

The documentation about quotekeys contains a sentence that surely needs
further clarification what it means (what is a simple string, what does
it do with not simple strings):

    A defined false value will avoid quoting hash keys when it looks
    like a simple string.

Here is the program:

perl -le 'use Data::Dumper; use Test::More; print $Data::Dumper::VERSION;
for my $useperl (0,1){
  for my $useqq (0,1){
    for my $quotekeys (0,1){
      my $dd = Data::Dumper->new([{useperl=>$useperl,useqq=>$useqq,quotekeys=>$quotekeys,42,42,foo=>"bar"}])->Useperl($useperl)->Useqq($useqq)->Quotekeys($quotekeys)->Dump;
      mydump($dd);
    }
  }
}
sub mydump {
  my($dd) = @_;
  # diag $dd;
  my $mydump = "";
  for my $opt (qw(useperl useqq quotekeys)){
    $mydump .= sprintf " %s %d", $opt, $dd =~ /$opt.*=>\s*(\d+),?/m;
  }
  diag sprintf "%s ==> %-16s %s\n", $mydump, $dd =~ /^\s+(.*foo[^,\n]*)/m, $dd =~ /^\s+(.*42[^,\n]*)/m;
};
'
2.149
#  useperl 0 useqq 0 quotekeys 0 ==> foo => 'bar'     '42' => 42
#  useperl 0 useqq 0 quotekeys 1 ==> 'foo' => 'bar'   '42' => 42
#  useperl 0 useqq 1 quotekeys 0 ==> foo => "bar"     "42" => 42
#  useperl 0 useqq 1 quotekeys 1 ==> "foo" => "bar"   "42" => 42
#  useperl 1 useqq 0 quotekeys 0 ==> foo => 'bar'     42 => 42
#  useperl 1 useqq 0 quotekeys 1 ==> 'foo' => 'bar'   42 => 42
#  useperl 1 useqq 1 quotekeys 0 ==> foo => "bar"     42 => 42
#  useperl 1 useqq 1 quotekeys 1 ==> "foo" => "bar"   42 => 42

For a reference here the output of 2.145 that came with 5.18.1:

2.145
#  useperl 0 useqq 0 quotekeys 0 ==> foo => 'bar'     '42' => 42
#  useperl 0 useqq 0 quotekeys 1 ==> 'foo' => 'bar'   '42' => 42
#  useperl 0 useqq 1 quotekeys 0 ==> foo => "bar"     42 => 42
#  useperl 0 useqq 1 quotekeys 1 ==> "foo" => "bar"   42 => 42
#  useperl 1 useqq 0 quotekeys 0 ==> foo => 'bar'     42 => 42
#  useperl 1 useqq 0 quotekeys 1 ==> 'foo' => 'bar'   42 => 42
#  useperl 1 useqq 1 quotekeys 0 ==> foo => "bar"     42 => 42
#  useperl 1 useqq 1 quotekeys 1 ==> "foo" => "bar"   42 => 42



-- 
andreas




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About