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

Re: Overloading Perl's Built-In's

by dchetlin (Friar)
on Jan 12, 2001 at 13:57 UTC ( #51333=note: print w/replies, xml ) Need Help??


in reply to Overloading Perl's Built-In's

This is an excellent and well thought out question. Solid ++. The answer is, you haven't done anything wrong. The documentation is a little unclear on this point, but certain Perl operators are overridable, and certain others aren't. In perl 5.6.0 and earlier, chomp was not overridable. So nothing you can do will get your subroutine to be called in place of the built-in.

However, our very own ctweten noticed this in September and discovered that there's no reason at all chomp (and chop) shouldn't be overridable, and patched perl to make that possible. This change was too late for 5.6.0, but is in 5.7.0 and has been integrated into the 5.6.1 trial release 1. So, pending something horrifically bizarre, your first test module should work just fine on 5.6.1.

In the meantime, I would suggest playing around with a different operator to learn how to overload built-ins. If you're interested and have a copy of the source for your version of perl sitting around, the way to figure out what's overridable is by this one-liner, courtesy Nick Ing-Simmons:

perl -ne 'print "$1\n" if /return\s*KEY_(\w+)/' toke.c

Hope this is helpful. Keep up the good work.

-dlc

Replies are listed 'Best First'.
Patched Perl and toke.c
by bbfu (Curate) on Jan 12, 2001 at 14:11 UTC

    Thanks for your help! I'm definately going to have to look at toke.c when I get the chance (tomorrow at work =).

    Is Perl 5.7 out already? I knew about 5.6 and I thought they were working on 5.6.2... Did they skip over 5.6.2 and are comming back to it after 5.7? Maybe I should start reading Perl News, too! =) And I only just found this site!

      Is Perl 5.7 out already
      • 5.7 is the development branch that will eventually produce 5.8.

      • 5.6.x is the maintenance and bugfix branch for 5.6.
      --
      <http://www.dave.org.uk>

      "Perl makes the fun jobs fun
      and the boring jobs bearable" - me

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://51333]
help
Chatterbox?
[marioroy]: Disciplus My wife and I went on vacation. At work, I was stuck polling SNMP from 20 million devices. It would hang at 80,000. On the mist boat, hear a voice to enable grace in the design that 10x and more performance awaits.
[Lady_Aleena]: Women need challenges too karlgoethebier. 8)
[marioroy]: s/hear/heard/
[karlgoethebier]: Discipulus: No. See https://en. wikipedia.org/ wiki/Tribe_( Native_American)
[karlgoethebier]: They took Unix from some aliens
[marioroy]: Perl is so powerful that it can poll 40 metrics from 20 million devices in 40 minutes using 4 nodes only.
[karlgoethebier]: http://www. uncoveror.com/ aliens.htm
[Lady_Aleena]: marioroy, I can't decide whether or not to move my RolePlaying:: Random:: modules to just Random::. I'm not as sophisticated as most here.
[marioroy]: Naming things can be difficult, sometimes more so that the actual code :)
[karlgoethebier]: Lady_Aleena: You need to jump to some conclusion

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2017-05-29 08:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?