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

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Thursday July 10, 2008
11:38 AM

What Do You Think This Will Print?

[ #36890 ]

Without actually running the program, what do you think the following prints?

print
<<print;
exit
print
<<print;
exit
print

Update: Thanks to pudge for fixing the bug which made the above code hard to display.

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.
  • Just "exit". Then it defines an unused string that also consists of "exit". Now I'll go see if I'm right.

    --
    J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
    • Curiously, the output is different on my MacBook (but also wrong).

      • That is indeed strange. My 5.10.0 just printed exit, as I predicted. :)

        --
        J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
  • I thought it'd print "\nexit\n\n" (because of your extra newlines). It's a cute problem though, certainly made me think for a moment. Better rewritten as:

    print << END;

    exit

    END;

    << STRING;

    exit

    STRING;

    • Actually, the extra newlines were an artifact of a bug in use.perl. Pudge has fixed it.

      That being said, yesterday I found that my MacBook was giving me a "Can't find string terminator" error but the Solaris box I was working on was printing:

      exit
      print
      <<print;
      exit

      This morning, the Solaris box is printing the right thing, but I had to reboot due to a "security upgrade" and now I can't reproduce the error :(

  • print
    <<print;
    exit
    print
    <<print;
    exit
    print

    Thanks Ovid, looks like I found the bug and fixed it. Feel free to amend your journal entry.