in reply to Re^4: "Pro Perl's" Redirecting Filehandles - Unexpected Result (why)
in thread "Pro Perl's" Redirecting Filehandles - Unexpected Result

">&STDOUT" is interpretted as ">& STDOUT" while "> &STDOUT" means something quite different. That is

open SAVEOUT, ">&STDOUT" # is the same as open SAVEOUT, ">& STDOUT" # is the same as open SAVEOUT, ">&", STDOUT

They all make SAVEOUT point to whatever output destination that the STDOUT file handle already points to. This is what the author was trying to teach you despite how it appeared in print. But

open SAVEOUT, "> &STDOUT" # is the same as open SAVEOUT, ">", "&STDOUT"

They both (try to) create a file called "&STDOUT" and have nothing to do with the STDOUT file handle.

The last example in each of those sets is different if you have a pretty old version of Perl that doesn't support "three-argument open", of course.

- tye        

Replies are listed 'Best First'.
Re^6: "Pro Perl's" Redirecting Filehandles - Unexpected Result (why)
by ack (Deacon) on Feb 28, 2008 at 20:23 UTC

    Ah! Thanks, tye...and parv, too...you both gave that excellent feedback. Now I understand...though I believe the author may have had a typo. But what you presented makes perfect sense...and reflects accurately exactly what happened. Learning things is great...especially when a mis-step leads to a much deeper appreciation of what's going on.

    Thanks again to you both.

    Sorry it took so long for me to get back to this...I only get an occasional chance, at work, to go out here and see how the Monestary is doing. I just discovered how to find all my previous nodes...that helps. This such an awesome monestary.

    ack Albuquerque, NM