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?
|
---|