Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Peculiar hash behavior

by dd-b (Monk)
on Oct 02, 2021 at 18:08 UTC ( [id://11137199] : note . print w/replies, xml ) Need Help??


in reply to Re: Peculiar hash behavior
in thread Peculiar hash behavior

The array emulation is another one of those things I've read about a few times and never really understood well enough to be safe around :-) .

I've been wondering if Data::Dumper is getting on towards its freshness date; I've played with alternatives a bit. Simpler (Data::Dump) does seem to be what's needed, and the ddx function is nicely adapted for debug use, as it says was intended. There do seem to be packages for the environments I care about (FreeBSD, Ubuntu, Raspberry Pi).

Replies are listed 'Best First'.
Re^3: Peculiar hash behavior
by haukex (Archbishop) on Oct 02, 2021 at 19:31 UTC
    I've been wondering if Data::Dumper is getting on towards its freshness date

    Data::Dumper has been maintained by P5P alongside the core, so it's unlikely to go stale. It's just a bit unfortunate (IMHO) that its Useqq option is off by default - the other options I use in the linked post are mostly for "nicer" output, so as long as you write use Data::Dumper; $Data::Dumper::Useqq=1;, the module is fine. Data::Dump has prettier output by default, but if you look at its issue list you'll see it's not perfect either. There are lots of other dumper modules out there. The main things to remember are that you want the modules to give unambiguous output (hence Useqq) and that these modules are debugging aids and not data serialization tools.

Re^3: Peculiar hash behavior
by LanX (Saint) on Oct 02, 2021 at 19:07 UTC
    > The array emulation is another one of those things I've read about a few times and never really understood well enough to be safe around :-) .

    I think it helps to know that Perl4 had no references˛, so none of the - now normal - nested data-structures described in perldsc were available.

    With the introduction of Perl5 multi-dim hashes had to be kept for backwards compatibility, but are for most an unknown or obscure feature.

    But they are quite handy sometimes, you'd be surprised how many people tend to reinvent something like $h{ join(",",@dims) }= "x" which is essentially the same without a safer separator.°

    HTH! :)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

    °) a former boss was particularly proud to show me his "genius" trick to safe memory ...

    ˛) a lot had to be achieved with *type-globs (yuck)

      I remember the transition from Perl 3 to Perl 4, yeah. Lots of really useful new features.

        One might think that if you had been using Perl for that long you might have run across this feature before?

        Just sayin'      :)

        You remember Perl 3 ?!? Wait... are you brian d foy? Is this Larry?


        Give a man a fish:  <%-{-{-{-<

Re^3: Peculiar hash behavior
by ikegami (Patriarch) on Oct 04, 2021 at 19:30 UTC

    The array emulation is another one of those things I've read about a few times and never really understood well enough to be safe around :-) .

    $h{$x, $y, ...}
    is short for
    $h{join $;, $x, $y, ...}

    That's it.

    As long as your keys don't contain the value in $; (which is a control character by default), you can emulate multi-level hashes. It presumably uses less memory, but it might be a bit slower from concatenating the keys??? Of course, you're relying on the value of $; being safe.