Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^4: Anonymous Hash in Constructor

by Jim (Curate)
on Oct 19, 2012 at 19:20 UTC ( #1000023=note: print w/replies, xml ) Need Help??


in reply to Re^3: Anonymous Hash in Constructor
in thread Anonymous Hash in Constructor

Ah, but using strict and warnings demonstrates that nothing in the example is considered bizarro stuff that Perl will complain about.

Yes, indeed. Adding even more stuff to the example could introduce many new invaluable lessons. A complete, well-written Perl application could serve as a primer in good object-oriented programming. No doubt. But my point here was simply that I learned a little something by going a bit reduction-crazy. Noise reduction as pedagogical aid.

Disregarding the original topic of this thread entirely, I learned more still by playing with this…

{ package Class; sub new { bless {} } # sub new { bless [] } # sub new { bless \$scalar } # sub new { bless \&sub } sub Method { print "This is a method happening.\n" } } $object = Class->new; $object->Method;

Replies are listed 'Best First'.
Re^5: Anonymous Hash in Constructor
by tobyink (Abbot) on Oct 19, 2012 at 23:09 UTC

    Then this will blow your mind...

    sub x { print {+shift} "this is a method happening\n" } bless \*STDOUT, main::; (\*STDOUT)->x;
    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

      Then will this blow yours?

      sub new { print {+shift} "This is a method happening.\n" } bless \*STDOUT; (\*STDOUT)->new;

      Probably not.

      (I'd have to have this explained to me to understand it.)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1000023]
help
Chatterbox?
vrk adds oatmeal cookies to the platter on the sideboard.
[LanX]: evrybody can participate in a YAPC
choroba is still undecided what to present at YAPC
[LanX]: imagine the stock market if the choice for the second round would have been those two ...
[robby_dobby]: LanX: Not me. No YAPC in my country and the only one in Asia is so far off in Japan
[LanX]: Oh I thought "Misery" meant Missoury
[LanX]: where do you live?
[LanX]: YAPC Asia was renamed and you'd need to speak Japanese to be able to follow
[robby_dobby]: LanX: Misery :P
[robby_dobby]: Or India

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (12)
As of 2017-04-24 15:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (442 votes). Check out past polls.