Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL
Help

Subroutines > Argument Lists - Pg. 178

Perl considers some of its builtins (like link ) to be "more built-in" than others (like lock ), and chooses accordingly whether to call your subroutine of the same name. If the builtin is "strongly built-in", an ambiguous call will invoke it, in preference to any subroutine of the same name. On the other hand, if the builtin is "weakly built- in", an ambiguous call will invoke the subroutine of the same name instead. Even if these subroutines did always work as expected, it's simply too hard to main- tain code where the program-specific subroutines and the language's keywords overlap: sub sub sub sub sub crypt map chop close hex { { { { { return return return return return "You're in the tomb of @_\n" "You have found a map of @_\n" "You have chopped @_\n" "The @_ is now closed\n" "A hex has been cast on @_\n" } } } } } print crypt( qw( Vlad Tsepes ) ); for my $reward (qw( treasure danger) ) { print map($reward, 'in', $location); } print hex('the Demon'); print chop('the Demon'); # Subroutine or builtin? # Subroutine or builtin? # Subroutine or builtin? # Subroutine or builtin? There is an inexhaustible supply of subroutine names available; names that are more descriptive and unambiguous. Use them: