On Tue, Jul 10, 2001 at 12:32:16PM -0700, Paul wrote:
>
> --- Michael Fowler <[EMAIL PROTECTED]> wrote:
> > On Tue, Jul 10, 2001 at 10:19:43AM -0700, Paul wrote:
> > > open THIS, ">&THAT"
> >
> > This dups (see man 2 dup) fileno(THAT) and opens it with the
> > filehandle THIS. The THIS and THAT filehandles now refer to the same
> > file descriptor, and thus the same underlying file.
>
> But do they get seperate buffers?
Yes. Notice the syntax uses dup, dup only deals with file descriptors.
Buffers aren't introduced at that level.
To prove it:
> perl -MIO::Handle -we 'open(OUT, ">&STDOUT") || die; print OUT "out";
STDOUT->flush; sleep'
prints nothing.
> > > *THIS = *THAT
> >
> > This aliases all symbols named THIS to THAT. This means \$THIS eq
> > \$THAT, \%THIS eq \%THAT, \@THIS eq \@THAT, etc. (yes, I meant to
> > take the references to these values, in order to indicate they are
> > aliases, different names for the same values) and the filehandles
> > THIS and THAT go to the same file.
>
> But in this case, it's not just that they go to the same file --
> they're literally using the same "file structure pointer", to use the C
> lingo, aren't they?
Both variables have the same value. The values are identical in every way.
So yes, you get the same underlying file structure pointer.
> > The primary difference is that "*THIS = *THAT" are only visible
> > from Perl, they (for reasons that should be obvious if you think
> > about it) don't propagate to any external processes. Meaning, if
> > you want to redirect STDERR and STDOUT for a subprocess you have to
> > use the dup, or the fdopen (<&=fd), form of open, or equivalent.
>
> whoa.... are you sure about that?
> I could swear I've used aliasing to redirect subprocesses....
Given test.pl:
#!/usr/bin/perl -w
use strict;
open(OUT, ">out.txt") || die("open: $!");
*STDOUT = *OUT;
print STDOUT "this is test.pl\n":
system(qw(echo this is echo));
This is what you'd get:
> test.pl
this is echo
> cat out.txt
this is test.pl
If unsure, test.
Michael
--
Administrator www.shoebox.net
Programmer, System Administrator www.gallanttech.com
--