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

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

Thread Next
Prahlad Vaidyanathan
January 8, 2002 20:24
why does open()ing happen only at the <FD> line ?
Message ID:

Noticed this today :

open(FD,'sudo grep -h "Connect time" /var/log/message* | grep -v COMMAND |')  or die $! ;
# Do some stuff ...
while ( <FD> ) {
# do more stuff

In the above script (an attempt to check my ppp usage), the script
actually runs 'sudo' only when reading from the file (line #3) and not
when open() is run (line #1).

Why is that ? I am new to programming, so I don't know how other
languages would do this, but it seems counter-intuitive to me. I
presumed 'sudo' would be run when open() is run.


ps. Is it inadvisable to open the said file like this (see the script
above) ? If so, why ?

Prahlad Vaidyanathan <>

I love ROCK 'N ROLL!  I memorized the all WORDS to "WIPE-OUT" in

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