The point isn't what this JAPH does, but how it does it. Of course that's nearly always the case with these things, isn't it? ;) This was inspired by a recent Perlmonks discussion on rounding numbers without printf, though it has nothing at all to do with numbers, printf, or rounding.

require 5.8.0;$o="Just_another_Perl_Hacker";open$o,">",\$s;select $o;for($^){y$_$ $;s%....$%.\n%;die$_}

This JAPH requires Perl 5.8.0 or later to work properly.

Update: This JAPH uses a feature in Perl 5.8.0 or later that works differently in pre-5.8.0 Perl implementations. With Perl 5.8.0 or later, an in-memory file is created. In pre-5.8.0 Perls, a physical file is created. I have modified the script with the "require 5.8.0" directive to prevent this behavior, after investigating why Anonymous Monk's followup determined that the script still ran under pre-5.8.0 versions.


Dave


"If I had my life to live over again, I'd be a plumber." -- Albert Einstein

Replies are listed 'Best First'.
Re: An open can of worms JAPH
by Anonymous Monk on Nov 27, 2003 at 18:34 UTC
    This JAPH requires Perl 5.8.0 or later

    It works fine with Perl 5.6.1.

      As the original post stated, this is intended for Perl 5.8.0 or later.

      Under Perl 5.8.0, it won't create a physical file, but instead, a proper in-memory file. That is why I recommended 5.8.0 or later. ...well, that and the fact that I assumed that passing a scalar ref as a filename to a pre-5.8.0 Perl wouldn't even run.

      Out of curiosity, in your test on Perl 5.6.1, did it create a file named "SCALAR(0x1234567)" (or something like that) on your file system?

      Update: I have now modified the original JAPH by adding "require 5.8.0" to the beginning of the script so that people who fail to read the caviat won't inadvertantly run it on pre-5.8.0 versions. You can still remove that 'require 5.8.0' part to test it on pre 5.8.0 versions if you want. It won't hurt anything. But it probably will create a zero-byte file named "SCALAR(0x.....)" that you'll have to erase later. Again, no biggie.


      Dave


      "If I had my life to live over again, I'd be a plumber." -- Albert Einstein
        Out of curiosity, in your test on Perl 5.6.1, did it create a file named "SCALAR(0x1234567)" (or something like that) on your file system?

        I tested it with 5.6.1. It does create such a file, and it works.