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;
}

Get Perl 6 and Parrot Essentials, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.