http://qs321.pair.com?node_id=707267


in reply to Re^3: greater efficiency required (ls, glob, or readdir?)
in thread greater efficiency required (ls, glob, or readdir?)

It would take more than 7 lines to do the equivalent of or die $! when using cat.
die if $?;
only takes one short line.

Replies are listed 'Best First'.
Re^5: greater efficiency required (ls, glob, or readdir?)
by ikegami (Patriarch) on Aug 27, 2008 at 19:34 UTC
    Do you deem "Died at x.pl line y." acceptable for something that could be an I/O or spawning error? (It doesn't if it is and which it is).

      In this case, cat outputs its own error with what would be $!.

      cat: file-that-does-not-exist: No such file or directory

      It might be cleaner to "exit 1 if $?" rather than die to avoid the useless "Died" message (but then you don't get the line number).

      Update: Hmmm, when I hit 'reply', the node I replied to said only, Do you deem "Died at x.pl line y." acceptable?

      Oh, if you don't like the died message, replace it with
      exit 1 if $?;
      A few character strokes more, but still a very short line.

      And no, the program won't be silent. "cat" is perfectly able to tell the user why it can't read the file.

        True, I overlooked cat's error message. It'll still be silent for spawning errors, although those will be far less common.