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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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


In reply to Re: Overloading Perl's Built-In's by dchetlin
in thread Overloading Perl's Built-In's by bbfu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-19 11:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found