in reply to Function overloading in perl

Losely typed languages (like Perl). Have a difficult time implementing overloading. If I had this code:
my $a = 1; print OVERLOADED; sub OVERLOADED{ #This sub wants a char array return (shift eq "one"?1:0); } sub OVERLOADED{ #This sub is illegal in Perl #This sub wants an int return (shift == 1?1:0); }
Note that the very things that I would use to define overloading are not avalible. The same thing goes for lists.

Replies are listed 'Best First'.
Re^2: Function overloading in perl
by Anonymous Monk on Sep 07, 2010 at 22:17 UTC
    In perl, you have to do things the perl way, which means you can only have sub OVERLOADED
    sub OVERLOADED { ## do different things depending on arguments }
    you can't blindly copy the c/c++ concept of function signatures/overloading and expect it to work