5.4 Subroutine Stubs

     

To declare a subroutine without defining it you give it a body consisting of nothing but the . . . (or "yada, yada, yada") operator. So, all the preceding examples that look like pseudocode with { . . . } for their body are actually valid subroutine declarations.

 sub stubbly (Str $name, Int ?$days) { . . . } 

When you later define the subroutine, the signature and defined traits must exactly match the declaration.

 sub stubbly (Str $name, Int ?$days) {     print "$name hasn't shaved in $days day";     print "s" if $days > 1; } 



Perl 6 and Parrot Essentials
Perl 6 and Parrot Essentials, Second Edition
ISBN: 059600737X
EAN: 2147483647
Year: 2003
Pages: 116

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net