in reply to Why shows B::Deparse __END__ as __DATA__?

There's absolutely no difference between __END__ and __DATA__, just like there's absolutely no difference between for and foreach.

$ perl -MO=Deparse -e'foreach (@a) { }' foreach $_ (@a) { (); } -e syntax OK $ perl -MO=Deparse -e'for (@a) { }' foreach $_ (@a) { (); } -e syntax OK
$ perl -MO=Deparse -e'for (a(); b(); c()) { }' for (a(); b(); c()) { (); } -e syntax OK $ perl -MO=Deparse -e'foreach (a(); b(); c()) { }' for (a(); b(); c()) { (); } -e syntax OK

Since there's no difference, Deparse has no idea which one was used in the source, so it uses whatever it finds most idiomatic.

Replies are listed 'Best First'.
Re^2: Why shows B::Deparse __END__ as __DATA__? (BUG #1)
by LanX (Saint) on Oct 12, 2014 at 12:45 UTC
    and here a real bug:

    lanx@nc10-ubuntu:/tmp$ cat end_pkg.pl print <DATA>; package TST; 1; __END__ end lanx@nc10-ubuntu:/tmp$ perl -MO=Deparse end_pkg.pl print <DATA>; package TST; '???'; end_pkg.pl syntax OK lanx@nc10-ubuntu:/tmp$ perl end_pkg.pl end lanx@nc10-ubuntu:/tmp$ perl -MB::Deparse -E 'say "$B::Deparse::VERSION +"' 0.83

    update
    took a look into current source of B::Deparse version 1.20 and it has the same code regarding __DATA__

    Cheers Rolf

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

      and here another related bug, B::Deparse appends the wrong __DATA__ from the used module, cause of package confusion.

      lanx@nc10-ubuntu:/tmp$ cat use_wrong.pl use wrongdata; print <DATA>; package TST; 1; __END__ end lanx@nc10-ubuntu:/tmp$ perl use_wrong.pl end lanx@nc10-ubuntu:/tmp$ cat wrongdata.pm package TST; 1; __DATA__ wrongdata lanx@nc10-ubuntu:/tmp$ perl -MO=Deparse use_wrong.pl use wrongdata; print <DATA>; package TST; '???'; package TST; __DATA__ wrongdata use_wrong.pl syntax OK

      Cheers Rolf

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

      update

      see Re^2: Why shows B::Deparse __END__ as __DATA__? for explanation!

        no_data.pl has no DATA section at all, but B::Deparse includes the part from the used module.

        This example shows that neither \*main::DATA nor \*last_pckg::DATA can be reliably used without further information.

        We either need a mechanism to get the real filehandle of the current file (maybe thru B ?) or a way to identify the file associated to those filehandles (for check against $0)

        lanx@nc10-ubuntu:/tmp$ cat no_data.pl use wrong_data; print <DATA>; lanx@nc10-ubuntu:/tmp$ cat wrong_data.pm 1; __DATA__ wrong main::DATA lanx@nc10-ubuntu:/tmp$ perl -MO=Deparse no_data.pl use wrong_data; print <DATA>; __DATA__ wrong main::DATA no_data.pl syntax OK lanx@nc10-ubuntu:/tmp$ perl no_data.pl wrong_main::DATA

        for completeness: The deparsed code will produce the same results now in this special case!

        Cheers Rolf

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

Re^2: Why shows B::Deparse __END__ as __DATA__?
by LanX (Saint) on Oct 12, 2014 at 03:05 UTC