in reply to Re^4: how do I "initialize" $_ (updated)
in thread how do I "initialize" $_

I tested this with my Perl
C:\Users\mmtho\Documents\PerlProjects>perl -v This is perl 5, version 24, subversion 3 (v5.24.3) built for MSWin32-x +64-multi-thread (with 1 registered patch, see perl -V for more detail) ...
And I found out that Perl has changed how it deals with <DATA>.
This works with Perl 5.24:
#!/usr/bin/perl use strict; use warnings; while (my $line = <DATA>) { print $line; } __DATA__ aBC XYAS

Replies are listed 'Best First'.
Re^6: how do I "initialize" $_
by AnomalousMonk (Archbishop) on Oct 13, 2018 at 06:21 UTC

    In an oversight since corrected, I neglected to mention that the code here was run under Perl version 5.8.9.

    I tried

    while (my $line = <DATA>) { print $line; }
    with my original  __DATA__ both with and without a newline after the 0 on the final line and with strictures and warnings fully enabled and under 5.8.9 and saw no difference in behavior (and no warnings). The reason is easy to see from a deparse:
    c:\@Work\Perl\monks\Marshall>perl -MO=Deparse,-p t_read_DATA_2.pl use warnings; use strict 'refs'; print("perl version: $] \n\n"); while (defined((my $line = <DATA>))) { do { print($line) }; } __DATA__ line the first second line penultimate line is line 3 t_read_DATA_2.pl syntax OK 0
    The defined test is automatically added.


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

      Interesting.

      In any event apparently defined() on the <DATA> file handle is not needed - or at least not any more.

      Update: I haven't been able to reproduce this warning on my current Perl 5.24 version. From what I remember the warning was unusually specific in what it said - this was very specific. To my knowledge, I never did actually try Perl code that would cause the problem that was warned about. This was a warning about something that could potentially happen - not an error. This situation did not occur in my source code. I just took Perl at "its word" and adjusted my source code so that this warning went away.

      I think of Perl as a living, breathing, biological organism that evolves over time. It is completely possible that this was an extraneous warning about something that didn't really matter. At this point, I don't know. It could be that this warning was just emitted in one version of Perl and corrected in the next version. I've worked with a lot of versions of Perl. I don't have nor would I have saved the exact text of this warning.