Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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}}; }
Cheers,
Erik

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];

UPDATE:

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 [mail-archive.com]).

    --
    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.

      *blush*

      Thank you.

      Cheers,
      Erik

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://164812]
Approved by belg4mit
Front-paged by MeowChow
help
Chatterbox?
[perldigious]: That's awesome erix. One of my work friends, who coincidentally convinced me to learn Perl originally, has a Finnish pen-pal. I showed him this and he immediately wanted to send it along to her.
[perldigious]: Also coincidentally, I'm currently in the middle of a winter storm that has dropped 1 foot of snow and is expected to drop another. I might have to adapt this for customers/vendors who come visit and put it at the beggining of every presentation I give.
[Discipulus]: the photo was removed... Cyrano de Berjerac was not of the same idea..
[stevieb]: perldigious: video near our hq in Montreal. Here in Calgary, it's -28c... we've only got 3" of snow so far, but there are several feet in the mountains already

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (14)
As of 2016-12-06 16:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (112 votes). Check out past polls.