Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Polymorphism JAPH

by cristian (Hermit)
on Apr 13, 2005 at 17:23 UTC ( #447517=obfuscated: print w/replies, xml ) Need Help??

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,

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://447517]
Approved by ktross
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2018-07-22 05:36 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (452 votes). Check out past polls.