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

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

Thread Next
From:
Prahlad Vaidyanathan
Date:
January 8, 2002 20:24
Subject:
why does open()ing happen only at the <FD> line ?
Message ID:
20020108143614.GA4074@marvin.clone
Hi,

Noticed this today :

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

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.

pv.

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

-- 
Prahlad Vaidyanathan <slime@vsnl.net>

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

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About