Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: AUTOLOAD - the good, the bad, and the ugly

by dragonchild (Archbishop)
on Oct 15, 2004 at 04:23 UTC ( [id://399393]=note: print w/replies, xml ) Need Help??


in reply to Re: AUTOLOAD - the good, the bad, and the ugly
in thread AUTOLOAD - the good, the bad, and the ugly

A nit.
my $method = $method_and_structure[@method_and_structure-1];
is better written (and slightly faster) as
my $method = $method_and_structure[-1];

But, most examples I've seen tend to do the one of the following:

my $method = (split '::', $AUTOLOAD)[-1]; #### my ($method) = $AUTOLOAD =~ /([^:]+)$/; #### (my $method = $AUTOLOAD) =~ s/.*:://;

In that last, you want to use .* as opposed to .*? because you want it to be as greedy as possible.

Update: Fixed slice to scalar access.

Update: Added parentheses in second-to-last example.

Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Replies are listed 'Best First'.
Re^3: AUTOLOAD - the good, the bad, and the ugly
by ihb (Deacon) on May 05, 2005 at 00:29 UTC

    I tend to do my ($method) = $AUTOLOAD =~ /.*::(.*)/s; which I find nice and clean.

    ihb

    See perltoc if you don't know which perldoc to read!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://399393]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2024-04-26 02:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found