in reply to Re^4: STDERR Restore after redirect
in thread STDERR Restore after redirect

From poj's reply:   SEND: { ... }

What is the SEND() for? What does it do?

In this case, SEND is not a function call (as the () argument list operator you use would suggest), but is the label of a block that establishes a scope for the local-ization of changes to the global STDOUT and STDERR system file handles. (Update: See Compound Statements and Basic BLOCKs, both in perlsyn.)

The label is not syntactically or semantically necessary for the establishment or operation of the scope in this case, but serves a purely documentary function: What's happening in the block? We're SENDing something. At the end of the block (or scope), the values of STDOUT and STDERR that existed before entering the block/scope are automatically restored.

Update: If you haven't already, take a look at Coping with Scoping by Dominus, especially the discussions of local and package variables.


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^6: STDERR Restore after redirect (updated)
by tultalk (Monk) on Apr 28, 2018 at 20:31 UTC

    And what to make of this?

    When to Use my and When to Use local Always use my; never use local.

      Always use my; never use local.

      Personally, I always choose lexicals over package-global variables if I have a choice. But if you're working with STDOUT and STDERR, then that's what you've got to work with, and local is the right tool. (And don't blame the poor, innocent  SEND: { ... } block if you've got code somewhere that's stepping on your global file handles. :)


      Give a man a fish:  <%-{-{-{-<