Help for this page

Select Code to Download


  1. or download this
    
    sub foo (
    ...
                      
        @rest         # slurp up any remaining arguments
    ) { .... }
    
  2. or download this
        sub f ($x :foo, $y :bar(baz) bar2(baz2), ...) { ... }
    
  3. or download this
        my $x :foo;
        my $y :bar(baz) bar2(baz2);
    
  4. or download this
        my ($x, $y) :foo(foo_arg) :bar(bar_arg);
    
  5. or download this
        use attributes ();
        my ($x,$y);
        attributes->import(, __PACKAGE__, \$x, "foo(foo_arg)", "bar(bar_ar
    +g)");
        attributes->import(, __PACKAGE__, \$y, "foo(foo_arg)", "bar(bar_ar
    +g)");
    
  6. or download this
        sub foo (
                 $pos1,  # positional parameter; consumes 1 arg
    ...
                :$name2, # named parameter, consumes ("name2", value) arg 
    +pair
                @rest, # consumes all unrecognised name/value pairs
            ) { ... }
    
  7. or download this
        ?$x       peek ahead to the next arg
        ??$x      peek ahead and see if there is a next arg
        ?@a       peek ahead and copy all remaining args
        ?%h       peek ahead and copy all remaining key/val arg pairs
        ?{ code } execute some code without consuming any args
    
  8. or download this
       sub foo {
            # the lexical vars $a, @b and %c are aliased to the things poi
    +nted
    ...
    
            *%g
        ) { ... }
    
  9. or download this
        sub f(
                $self isa Foo::Bar,         # croak unless $self->isa('Foo
    +::Bar');
    ...
                $f    is \@,                # croak unless  array ref
                $aref as ref ? $_ : [ $_ ]  # coercions: maybe modify the 
    +param
        ) { ...};
    
  10. or download this
        sub f (Int $x) { ... }
    
  11. or download this
        sub f ($x)  {  croak unless
                                 defined $x
    ...
                              && $x =~ /\A-?[0-9]+\Z/;
                        ....;
                    }
    
  12. or download this
        sub f (Some::Arbitrary::Class $x) { ... }
    
  13. or download this
        sub f ($x)  {  croak unless
                                 defined $x
    ...
                              && $x->isa(Some::Arbitrary::Class);
                        ...;
                    }
    
  14. or download this
        sub f ($x where * < 10*$y) { ... }
    
  15. or download this
        sub f($a, $b, $c, ... ) { BODY; }
    
  16. or download this
        sub f {
            my $a = ....;
    ...
            ....;
            BODY;
        }