Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: File Input and Output

by gariki (Initiate)
on Jul 11, 2001 at 22:26 UTC ( #95793=note: print w/ replies, xml ) Need Help??


in reply to File Input and Output

need small help, when i am trying to read from the file and write to the file it is working perfect, but when i am trying to read from the key board and write to the file the file is not being written. There are no problems with opening files i guess. can u help.. sorry for asking such trivial question. and if u know of any message board for perl please let me know so that i may post my questions there in future.. n here is my code... _______________

#!/usr/bin/perl -w #open(IN, "input.txt"); open(OUT, ">out.txt"); while( <STDIN>) { print $_; print OUT $_; } #close (IN); close (OUT);
______________________ thanks Gariki.


Comment on Re: File Input and Output
Download Code
Re: Re: File Input and Output
by marlowe (Beadle) on Feb 06, 2002 at 02:10 UTC
    try this. #!/usr/bin/perl -w use strict; my $output_file = "out.txt"; my $user_input = ""; my $quit_code = "quit\n"; open(OUTPUT, ">$output_file) || die "Unable to open $output_file for writing: $!\n"; while ($user_input ne $quit_code) { print "Enter some text: "; $user_input = <STDIN>; print OUTPUT $user_input; } close(OUTPUT) || die "Unable to close $output_file: $!\n;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://95793]
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: (10)
As of 2014-09-02 12:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (22 votes), past polls