in reply to Some questions about CGI and optimizing Perl

on #2:

using @_ might be faster, but you'll probably find that it's much easier to keep your paramater order in line by using shift. It also allows you to set up defaults, and avoid warnings about using undefined parameters. Consider

$x = shift || 4; $p = shift || 'happy'; $q = shift || return 0;

Using @_ , you'll probably end up by checking if it is defined - which is a bit more messy looking IMHO

Replies are listed 'Best First'.
Re^2: Some questions about CGI and optimizing Perl
by hardburn (Abbot) on Aug 20, 2004 at 17:36 UTC

    One problem:

    $x = shift || 4;

    What happens if you really want to pass 0 in? It just won't work. So you still end up with a defined test (or apply the "defined or" patch):

    $x = shift; $x = defined $x ? $x : 4; # Or with the "defined or" patch $x = shift // 4; # Or check if there is anything left on @_ and shift if there is $x = @_ ? shift : 4;

    "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.