Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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

Comment on One Sigil to Hack them All . . .
Select or Download Code
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?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2014-09-18 20:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (124 votes), past polls