Friday, July 15, 2011

there is more than one way to access the parameters of the method you just called

sub my_function {
    my $val1 = shift();
    my $val2 = shift();
    my $val3 = shift();

    ...

}
does the same thing as
sub my_function {
    my $val1 = @_->[0];
    my $val2 = @_->[1];
    my $val3 = @_->[2];

    ...

}
but my favorite is
sub my_function {
    my ( $val1, $val2, $val3 ) = @_;

    ...
}

No comments:

Post a Comment