Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hey I am new at Perl and am trying desperately to open a text file, put the contents (one by one) into a seperate perl file. The Perl file will then get them via <STDIN> and act on them.I have no idea how to send the text file to the other file....Please help!!!!

edited: Mon Dec 16 16:59:42 2002 by jeffa - title change

  • Comment on Help reading text file (was: Help Please!!)

Replies are listed 'Best First'.
Re: Help reading text file
by cLive ;-) (Prior) on Dec 14, 2002 at 01:36 UTC
    You need to read in the file.

    read this

    If you still get stuck, post code showing where you've got to and we can point you in the right direction...

    cLive ;-)

Re: Help reading text file
by batkins (Chaplain) on Dec 14, 2002 at 04:07 UTC
    you really ought to clarify what you're trying to do. why would you read text, output it, and then read it in again?

    here's what you're probably trying to do:

    open(INPUT, "filename.txt"); while(<INPUT>) { # whatever's in here will be executed for every line - i'm assumin +g that's what "one by one" means } close(INPUT);
Re: Help reading text file
by dbp (Pilgrim) on Dec 15, 2002 at 09:49 UTC
    open IN, "infile.txt" or die "Error in r_open: $!\n"; open OUT, "outfile.txt" or die "Error in w_open:$!\n"; while (<IN>) { # do something with each line if you want print OUT $_; } close IN; close OUT;
    This assumes "one by one" means line by line. I don't understand what you mean by "The Perl file wil then get them via <STDIN>..." Get what?