in reply to ref to built-ins
You can create a wrapper to one, but you need to go through hoops to do it:
$substr = sub { if (@_ == 2) { return substr($_[0], $_[1]); } elsif (@_ == 3) { return substr($_[0], $_[1], $_[2]); } elsif (@_ == 4) { return substr($_[0], $_[1], $_[2], $_[3]); } else { require Carp; Carp::croak("Bad arguments for substr"); } }; print($substr->('abc', 1), "\n");
substr(@_)
and
substr($_[0], $_[1], $_[2], $_[3]) (unconditionally)
won't work, because builtins have prototypes, and the
&substr
trick to bypass the prototype doesn't work on builtins.
(&CORE::substr doesn't work either.)
|
|---|