[Purdue-pm] function parameter order question

Dave Jacoby jacoby.david at gmail.com
Thu Sep 26 10:10:06 PDT 2019

If you have a function that's going to read a file and return the output,
and perhaps trigger special behavior if no permissions or file doesn't
exist or something, how would you handle parameters?

What I am engaging right now looks like this.

    read_this_file( $special , $output, $input );

Where $output is an arrayref.

What I think is a better way of doing this is

    $output = read_this_file( $input , $special );

With the signatures feature in more recent Perls, you can set the signature

    sub read_this_file ( $input , $special = 1 ) { ... }

so that it defaults to the wanted behavior, or reverse it or not. Of
course, with old syntax, you could also do it.

sub read_this_file {
    my $file = shift;
    my $special = shift;
    $special //= 1;

So it's more the question of param syntax than function header syntax.

Do any of you have strong behavior?

Dave Jacoby
jacoby.david at gmail.com

I deal with my software the way I treat my eldritch abomination:
 It's not human, it's not even alive in the natural sense.
 It's nightmare-born and nightmare-shaped, and nightmares don't die easy.
  -- @yenzie
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.pm.org/pipermail/purdue-pm/attachments/20190926/80699a7b/attachment.html>

More information about the Purdue-pm mailing list