in reply to doubts about Data::Dumper output

dunno if i understand the Anonymous's answer..

BTW even Data::Dump::Streamer seems offer the same result: ie original_a pointing to alias (and not vice-versa)
#!perl use strict; use warnings; use Data::Dump::Streamer; my %dispatch = ( original_a => sub {print "AAA\n"}, ); $dispatch{alias}=\&{$dispatch{original_a}}; print Dump(\%dispatch); #OUTPUT $HASH1 = { alias => sub { use warnings; use strict 'refs'; print "AAA\n"; }, original_a => 'V: $HASH1->{alias}' }; $HASH1->{original_a} = $HASH1->{alias};


thanks
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: doubts about Data::Dumper output
by LanX (Saint) on Oct 06, 2014 at 12:27 UTC
    Please read Choroba's answer again, hashes have no order!

    You can't control which key is processed first by dumper.

    And both keys point to the same ref!

    You are expecting dumper to parse your original code to figure out which order was meant, but this information is lost within the hash!

    Cheers Rolf

    (addicted to the Perl Programming Language and ☆☆☆☆ :)

Re^2: doubts about Data::Dumper output
by Anonymous Monk on Oct 06, 2014 at 23:42 UTC

    dunno if i understand the Anonymous's answer...

    Ok, elaboration, Data::Dumper::Dumpxs() does the actual Dumpering ... and it emits a warning and does a bad job of Dumping the code reference.

    This is a genuine perlbug you found, you should report it -- as the link I linked earlier shows, bugs in Dumper can happen, if you report it, it will probably be fixed

    Streamer does a good job of dumping the code reference

    About the order, yeah, hashes are "unordered" what choroba/LanX said :) .... Data::Dumper does have a Sortkeys option .... as there is https://metacpan.org/pod/Data::Dump::Streamer#Controlling-Hash-Traversal-and-Display-Order

    Yes, lets burn some wood :) its a renewable resource

      I'm not sure what bug you're talking about. The fact that Data::Dumper can't dump code references is documented:
      "Data::Dumper" cheats with CODE references. If a code reference is encountered in the structure being processed (and if you haven't set the "Deparse" flag), an anonymous subroutine that contains the string '"DUMMY"' will be inserted in its place, and a warning will be printed if "Purity" is set.
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

        I'm not sure what bug you're talking about

        The weird  do{my $o} .... I forgot to realize that $Data::Dumper::Deparse wasn't turned on ... yeah

      About $Data::Dumper::Sortkeys: this seems to be unrelated in this case: it can force the default Perl ordering about keys or a special ordering providing a subroutine. Nothing to do with the order reference are created.

      thanks
      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.