Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

(redmist) Re: Reading a file

by redmist (Deacon)
on Mar 06, 2001 at 23:36 UTC ( #62560=note: print w/replies, xml ) Need Help??


in reply to Reading a file

Try this:

#!/usr/bin/perl -w use strict; open (FILE, "file.txt") or die "arrrrgh...$!\n"; while (<FILE>) { print; # pass to program here } close(FILE);
The reason you can do this is because while will read the file handle one line at a time. I am wondering what you mean by "passing it to another program." Could you just use a subroutine, or are you talking about a seperate utility?

redmist
Silicon Cowboy

Replies are listed 'Best First'.
Re: (redmist) Re: Reading a file
by Ido (Hermit) on Mar 07, 2001 at 00:11 UTC
    Maybe:
    open OUT,'|program' or die $!; open IN,'file.txt' or die $!; #if you don't need to process each line...I don't see why not printing + all the lines at once like: print OUT <IN>; #but if you must print one line at a time: while(<IN>){ #do whatever you want with the line. print OUT $_; } close OUT; close IN;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://62560]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2019-05-24 06:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (147 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!