print time

abez abez at abez.ca
Thu Jun 20 12:40:29 CDT 2002


In reference to the discussion on obfuscated perl and the final 
"print time" command. This link shows how you to can redefine built in
functions pointlessly as well!

http://perlcircus.com/site/subs.html

Create a subroutine that overrides a built-in function
use subs 'int';
sub int{
my $arg = shift;
return CORE::int($arg)*10;
}
print int("5.7");
RESULT: 50
DISCUSSION: Perl's built-in subroutines, like int can be redefined with
your own subroutines if you wish. Normally int would return the integer
portion of a number (in this case 5), but for some reason I wish to return
the integer times ten. In order to avoid a recursive call back to my own
subroutine I first call the original int in the CORE package, and then
multiply that by 10 before returning the final result. You could have
accomplished the same thing without using "int" as the name of your
subroutine -- "int_times_10" might seem like a good idea, but this trick
would be just the what you need to easily dynamically alter existing
functionality at runtime. 

-- 
ABeZ------------ ------- ------ - ---------- -- ------------
http://www.indexdirect.com/abez/ Abram Hindle (abez at abez.ca)
---- ------- ----------- ----------- - - ------ --------ABeZ




More information about the Victoria-pm mailing list