in reply to Re^2: improve script
in thread improve script

I must be too ignorant to see why STDOUT should be closed in a one-liner (???)

Anyway it's true is that chaining with and is a lazy way to avoid the already mentioned scalar comma operator:

  print, exit if cond

This seems to confuse many people, but has the same effect as

  do {print; exit} if cond

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Replies are listed 'Best First'.
Re^4: improve script
by afoken (Chancellor) on Nov 29, 2015 at 11:53 UTC
    I must be too ignorant to see why STDOUT should be closed

    Closing STDOUT was a simple way to make print fail, nothing more. There are several other ways how print can fail. A simple one is running out of disk space while STDOUT is redirected to a file. But I was too lazy to show creating, formatting, mounting, and filling a loop device just to show that print may fail. A third one is a disappearing block device - unplugging the wrong USB stick or harddisk. Number four: a failing disk. Number five: Disk quotas. Number six: Network disconnected while writing to a remote filesystem.

    in a one-liner (???)

    I never limited my post to one-liners. print and exit is problematic in one-liners as well as in scripts and modules, because it does not always exit, but it may look like it does. And, as posted in Re^5: improve script, the proper way to terminate a script with an error message is to use die. It writes the error message to where it belongs: STDERR.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)