Tuesday, April 8, 2014

Overriding the core function/ subrotine in perl

Though its not recommended but some times we are in need to change or extend the core functionality of inbuilt Perl function/ subroutine.

This can be easily implemented in the following way. I have created a small gist for changing the core functionality.( Just for fun)

#override the core subroutine (inbuilt function) of perl
BEGIN {
*CORE::GLOBAL::chdir = sub {
print "perl core funtion override sample";
}
*shove = \&CORE::push;
}
chdir ;
# CORE::chdir #"Still u can access the core function using this way\n";
shove @arr,1;
view raw coreIverride.pl hosted with ❤ by GitHub


You can read it more in perdoc .

No comments:

Post a Comment