in reply to Shift function and file opening

To supply a default filename.

Presumably this is not in a subroutine, so the shift references the @ARGV array containing the arguments from the command line. If there weren't any command line arguments then shift will return 'nothing' using the value undef. The undef value is 'false' so the final value of the logical expression shift || 'foo.html' is the right-hand part, 'foo.html'. Thus if no arguments $file gets set to 'foo.html' as a default value.

Replies are listed 'Best First'.
Re: Re: Shift function and file opening
by wirrwarr (Monk) on Sep 04, 2003 at 12:16 UTC
    There's a tiny trap here, because not unly undef evaluates to a false value.
    The values that evaluate to false are undef, 0, (), '0' (/me hopes he didn't forget one).
    Try this:
    perl -e "print (shift || 'foo.html');" 0 perl -e "print (shift || 'foo.html');" 1
    daniel.

      You forgot '' (the empty string), which also evaluates to false.

      --
      3dan