Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

One Sigil to Hack them All . . .

by erikharrison (Deacon)
on May 07, 2002 at 20:30 UTC ( #164812=CUFP: print w/replies, xml ) Need Help??

Sigils are hard to teach . . . very useful once you get someone to understand them, but that first step can be hard.

So why not get rid of them? That's what I set out to do, but instead wound up with STUPID (Sigils Turned Unified . . . uh . . . PID). STUPID will turn all four of Perl's sigils to the ampersand: &. You must assign to these variable in a more Python/Ruby - ish idiom, much like constructing anonymous arrays and hashes. In fact you are. They no londer interpolate in double quoted strings, and the implementation doesn't always work, AND you have to explicity dereference arrays/hashes. I couldn't think where this should really belong, but I figured this was the closest place in the Monestary. Enjoy, and don't take seriously.

sub AUTOLOAD : lvalue { (!ref ${$AUTOLOAD}) ? ${$AUTOLOAD} : (!wantarray) ? ${$AUTOLOAD} : (ref ${$AUTOLOAD} eq 'ARRAY' +) ? @{${$AUTOLOAD}} + : %{${$AUTOLOAD}}; }

ps. Yes I am aware that it uses sim-refs . . . it's just a joke man :-)

pps - Here's how to use this little gizmo . . .

#include AUTOLOAD from above . . . &foo = ['a', 'b', 'c']; print &foo->[0];


Alright! I don't know if anyone will ever read this, but just in case, it should be noted that Perl 5.8 fixes the problem with lvalue AUTOLOAD which required that you use the & funny character. Now this little snippet truly eliminates sigils entirely. I think. I actually haven't been able to test it, 'cause my computer is broken. /msg me if it works

Replies are listed 'Best First'.
Re: One Sigil to Hack them All . . .
by belg4mit (Prior) on May 07, 2002 at 22:15 UTC
    If you'd chosen $ it'd almost be PHP (except for the arrows).
    $foo = ['a', 'b', 'c']; print $foo->[2];

    (UPDATE: Heh, just realized that by using $ you avoid the need for symrefs :-D Of course tha means no & on subroutine calls)

    You might like English::Reference (spurred by the perl6 Highlander RFC discussion []).

    perl -pew "s/\b;([mnst])/'$1/g"

Re: One Sigil to Hack them All . . .
by pdcawley (Hermit) on May 09, 2002 at 17:51 UTC
    An lvalueable AUTOLOAD? You are sick, you know that don't you?

    Well done.


      Thank you.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://164812]
Approved by belg4mit
Front-paged by MeowChow
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2020-09-20 04:14 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (117 votes). Check out past polls.