Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example for override function in Perl

Could you please elaborate on override function in Perl. Some simple examples will be great to understand.

like image 786
user419534 Avatar asked Oct 22 '25 08:10

user419534


1 Answers

http://perldoc.perl.org/perlsub.html#Overriding-Built-in-Functions

Many built-in functions may be overridden, though this should be tried only occasionally and for good reason. Typically this might be done by a package attempting to emulate missing built-in functionality on a non-Unix system.

Overriding may be done only by importing the name from a module at compile time--ordinary predeclaration isn't good enough. However, the use subs pragma lets you, in effect, predeclare subs via the import syntax, and these names may then override built-in ones:

Example:

use subs 'chdir', 'chroot', 'chmod', 'chown';
chdir $somewhere;
sub chdir { ... }

Note: all of the above was extracted from the above link

like image 105
vol7ron Avatar answered Oct 25 '25 14:10

vol7ron