Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Obfuscated accessor

by bluescreen (Friar)
on Jan 27, 2009 at 20:16 UTC ( [id://739329]=CUFP: print w/replies, xml ) Need Help??

I was thinking if there any chance to write an accessor in just one line, and I came up with the following code. Of course I wouldn't use in a real project because its unreadable but it might worth sharing. The good thing is just replacing subroutine name creates a new accessor.
sub methodA { $_ = (caller(0))[3];s/.*\://; @_ > 1 ? $_[0]->{$_} = $_[ +1] : $_[0]->{$_} };

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (1)
As of 2024-04-25 19:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found