Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: This could have DWIM better

by radiantmatrix (Parson)
on Mar 01, 2006 at 21:48 UTC ( [id://533766]=note: print w/replies, xml ) Need Help??


in reply to This could have DWIM better

If you're worried about polluting other's namespaces, why don't you just override the function locally? I started with japhy's modification and produced this:

BEGIN { use subs 'length'; sub length(;$) { my $arg = @_ ? $_[0] : $_; defined($arg) ? CORE::length($arg) : undef; } }

You could even modularize this pretty easily:

package Func::Smarter; require Exporter; use vars qw'@ISA @EXPORT @EXPORT_OK'; use subs qw 'length' @ISA = 'Exporter'; @EXPORT_OK = qw'length'; sub length (;$) { my $arg = @_ ? $_[0] : $_; defined($arg) ? CORE::length($arg) : undef; } 1;

Then you could just use Func::Smarter 'length';, yes?

<-radiant.matrix->
A collection of thoughts and links from the minds of geeks
The Code that can be seen is not the true Code
I haven't found a problem yet that can't be solved by a well-placed trebuchet

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-19 21:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found