Concept : Educational OO Polymorphism practice with Japh
#!/usr/bin/perl package J ;sub new{$__=shift and(%__)=@_ and bless{1, $__{1}, },$__} package main; #Polymorphism J A P H package A ;sub new{$__=shift and (%__)= @_ and($___)= J->new( @_)and$___->{2}=$__{2}and bless($___,$__);} package P ;sub new{$__=shift and (%__)= @_ and($___)= A->new( @_)and$___->{3}=$__{3}and bless($___,$__);} package H ;sub new{$__=shift and (%__)= @_ and($___)= P->new( @_)and$___->{4}=$__{4}and bless($___,$__);} $o=H->new (1,Just,2,Another,3,Perl,4,Hacker); print "$o->{ $_} " foreach sort keys %{ $o } ;# Educational Concept

Replies are listed 'Best First'.
Re: Polymorphism JAPH
by jbrugger (Parson) on Apr 14, 2005 at 06:01 UTC
    Nice! works like a charm.
    But to be pickey, like merlyn said before, the proper way to write the origional JAPH = j Just another Perl hacker,
    Note the , and the cases. ;-)
    So with the help i got earlyer of this site i took the liberty of changing your nice script a little:
    o=H->new (1,"\152\165\163\164",2,"\141\156\157\164\150\145\162",3,"\120\145\162\154",4,"\150\141\143\153\145\162\54"); print "$o->{
    (i only break your nice lay-out now :-)

    *update* ok, as cog wrote below.... it is:
    o=H->new(1,"\112\165\163\164",2,"\141\156\157\164\150\145\162",3,"\120 +\145\162\154",4,"\150\141\143\153\145\162\54"); print "$o->{ $_}"



    "We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.
      the proper way to write the origional JAPH = just another Perl hacker,

      The proper way actually has the "j" uppercased, and doesn't have a trailing space (you don't mention this, by I see the obfu prints it).

      print "Just another Perl hacker,";

      That prints it out the proper way.

      Realy the script search show the polymorphism and inheritance this explained with 4 level of call new sub object. I generate 4 level de inheritance for J A P H , is for the art.It's for what look more nice. The idea es practice OO with JAPH - Just another Perl hacker,