Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^4: STDERR Restore after redirect

by tultalk (Monk)
on Apr 28, 2018 at 16:23 UTC ( [id://1213730]=note: print w/replies, xml ) Need Help??


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

<Hi>

Thanks for input. As I stated before I already tried the local and the results were the same. So I tried again.

Going through block of code and eliminating items step by step, commenting out #print "stdout 2\n"; and the program executed and printed html form as desired. Have no idea what effect that line could have to cause the failure. Ir was added for testing after some other problem.

Bizarre/p>

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

Replies are listed 'Best First'.
Re^5: STDERR Restore after redirect (updated)
by AnomalousMonk (Archbishop) on Apr 28, 2018 at 16:57 UTC

    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:  <%-{-{-{-<

      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:  <%-{-{-{-<

Re^5: STDERR Restore after redirect
by poj (Abbot) on Apr 28, 2018 at 17:06 UTC

    see BLOCKS

    SEND: is just an optional LABEL to make the block more visible. The block {} restricts the scope of the local().

    poj

      Hi. Thanks all. Moving on to the STARTTLS mode.

      If I should start new topic, warn me.

      AUTH PLAIN failed: 554 Security failure
      Server said: 554 Security failure
      

      MIME::Base64 encode/decode

      my $encodedString = "AUTH PLAIN " . encode_base64(join("\0", $auth->{user}, $auth->{ +user}, $auth->{password}), $CRLF); my $decodedString = decode_base64($encodedString) +; warn("decodedString '$decodedString'");

      Encode produces:

      AUTH PLAIN d2VibWFzdGVyXEBid21qY20udXMAd2VibWFzdGVyXEBid21qY20udXMAd21 +ANDA5MTNXTQ==

      Decode produces:

      D<5ݕѕqݵݕѕqݵݵ ]4

      I thought the decoded string would be that same as the input string.No?

        Why would prepending  "AUTH PLAIN " to the encoded string leave the encoding unchanged so that decoding would remain symmetric?

        c:\@Work\Perl\monks>perl -wMstrict -le "use MIME::Base64; ;; use Data::Dump qw(pp); ;; my $encoded = encode_base64('Aladdin:open sesame'); ;; my $decoded = decode_base64($encoded); print qq{A: '$decoded'}; ;; $encoded = 'AUTH PLAIN ' . $encoded; $decoded = decode_base64($encoded); print 'B: ', pp $decoded; " A: 'Aladdin:open sesame' B: pack("H*","0144c73cb0083505b1859191a5b8e9bdc195b881cd95cd85b594")

        Update: And yes, this does look like a bit of a new topic...


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1213730]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2024-04-24 23:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found