Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Polymorphism JAPH

by cristian (Hermit)
on Apr 13, 2005 at 17:23 UTC ( [id://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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: obfuscated [id://447517]
Approved by ktross
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-24 18:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found