Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • So it can serialize closures without losing information?
    • by demerphq (2831) on 2005.05.25 12:02 (#40722) Homepage Journal
      Yep. Eg:

      D:\Development>perl -MDDS -e"my $closure=do{ my $x=100; sub { $x++ } }; Dump $closure"

      my ($x);
      $x = 100;
      $CODE1 = sub {
                            $x++;
                        };
      • The following code crashes.

        #! /usr/bin/perl
        use strict;
        use Data::Dump::Streamer;

        Dump [
          map {
            my $x;
            my $x_eclipse_1;
            sub {$x}, sub {$x_eclipse_1};
          } 1, 2
        ];

        I thought about trying to solve this with intelligent mangling, but there is always a boundary case. For instance if you mangle anything with $x_eclipse_1 in some way (eg make it $x__eclipse_1), what if there is a global variable $x_eclipse_1? Now you've changed semantics or else get a crash.

        After

        • The following code crashes.

          Shoot. Yep. It does. And it highlights what I forgot to document: the subs being dumped shouldn't mix the use of dynamics and lexicals with the same name, and that its is unwise to use variables matching /_eclipse_\d+$/. (Which personally I think is not such a terrible restriction, albeit not at all ideal.)

          Dealing with the former is actually very tricky, and probably wont ever be solved properly. A good example is

          my $a=sub { $a++ };

          The second issue regarding eclipsed

      • #! /usr/bin/perl
        use strict;
        use vars '@x_eclipse_1';
        use Data::Dump::Streamer;

        Dump [
          map {
            my @x;
            sub {$x[0]}, sub {$x_eclipse_1[0]};
          } 1, 2
        ];
        Gets horribly confused.