develooper Front page | perl.fwp | Postings from April 2003

Re: Fun with Perl, for a change

From:
Abigail
Date:
April 11, 2003 01:41
Subject:
Re: Fun with Perl, for a change
Message ID:
20030410191912.GB6180@abigail.nl
On Thu, Apr 10, 2003 at 04:47:19PM +0100, Simon Cozens wrote:
> Rob Dixon:
> > Can somebody suggest how I might resolve the following?
> > If I make a GET request to a server with a URL like
> >     http::/ww.domain.com/path/path/name
> > [... ordinary programming question ...]
> 
> I must be on the wrong list. See, I thought this was fun-with-perl, and
> boring programming questions just aren't fun. Even so, we've had nothing but
> this sort of thing for the past two months or so. I suggest we have some more
> fun.
> 
> Here's a piece of fun I came up with the other day. Who can work out how it
> works?
> 
>     use Ruby;
> 
>     $x = 10; 
>     print $x;                        # 10
>     $x++; 
>     $x.puts;                         # 11
>     $x.class.puts;                   # Fixnum
>     $x.class.class.puts;             # Class
> 
>     $x->upto(20, sub { $_.puts });   # 11, 12, 13, .. 20
> 
>     $y = "Hello, world";
>     $y->puts;                        # Hello, world
>     $y.class.puts;                   # String
>     $y->length.puts;                 # 12
> 
> No source filters, XS or any other Deep Magic is involved. It's all pure
> Perl.


Without reading the rest of the replies that might contain a spoiler,
or peeking into Ruby.pm, my first guess is 'overload::constant'. 
Since the post comes from Simon, I contemplated UNIVERSAL::AUTOLOAD,
but I don't think you would be able to pull off the '$x.puts' that
way.


Abigail



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