develooper Front page | perl.fwp | Postings from September 2001

Re: World's Largest JAPH

Thread Previous | Thread Next
From:
Ronald J Kimball
Date:
September 9, 2001 06:21
Subject:
Re: World's Largest JAPH
Message ID:
20010909092112.A19288@linguist.thayer.dartmouth.edu
On Sun, Sep 09, 2001 at 12:18:22PM +1000, Andrew.Savige@ir.com wrote:
> The JAPH below is generated from this program:
>   open 0;
>   $/ = undef;
>   $x = <0>;
>   close 0;
>   $x =~ tr/!-~/#/;
>   print $x;
> I noticed this "zero file handle trick" in Acme::Bleach,
> but it does not seem to be mentioned in the docs.
> Does anyone have more information on this trick?

perlfunc:

  open FILEHANDLE,EXPR

  open FILEHANDLE

    Opens the file whose filename is given by EXPR, and associates it with
    FILEHANDLE.  If FILEHANDLE is an expression, its value is used as the
    name of the real filehandle wanted.  If EXPR is omitted, the scalar
    variable of the same name as the FILEHANDLE contains the filename.

perlvar:

  $0

    Contains the name of the file containing the Perl script being
    executed.

So, open(0) opens the filehandle 0 on the file named in the variable $0,
which happens to be the file that is being executed.


Ronald

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About