develooper Front page | perl.beginners | Postings from January 2002

Re: why does open()ing happen only at the <FD> line ?

Thread Previous | Thread Next
Prahlad Vaidyanathan
January 9, 2002 21:16
Re: why does open()ing happen only at the <FD> line ?
Message ID:

On Wed, 09 Jan 2002 Michael Fowler spewed into the ether:
[-- snip --]
> How did you go about determining this?  As far as I know, this is not the

I'll explain. This is something I just ran. 

[ My /var/log/messages is a test file containing 1 line only. ]

open(FD,"sudo less /var/log/messages |") ;
print "test\n" ;
my $line = <FD> ;
print "$line\n" ;
print "test #2\n" ;

$ ./
    [waits for password here]
Jan  6 06:51:13 marvin syslogd 1.4-0: restart.

test #2

As you can see, it runs 'sudo' _after_ printing "test\n". ie. when it
reads from the file.

>     perl -wle 'open(F, q{perl -wle "print STDERR q{test}" |") || die; sleep;'
> If the command was only executed when F is read from you'd never see "test". 
> However, when I run the above, I see "test".  The sleep is in there to prove
> it's not being run due to the implicit close at the end of the script.

Yes. I agree. But, I can't, for the life of me, figure out why my tests
with sudo work the way they do. Is it some system-specific quirk ?

> > ps. Is it inadvisable to open the said file like this (see the script
> > above) ? If so, why ?
> Opening it like this is fine, but I would use Perl to do the grepping, not
> several invocations of grep.

I changed that. But, I was wondering if there is a 'sudo' thingy for
perl ;-)

Thanks for the help, but I'm still puzzled.

Prahlad Vaidyanathan <>

"May the forces of evil become confused on the way to your house."
-- George Carlin

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About