open(INFILE, "rmaccess1.txt") or die "Can't open rmaccess1.txt: $!"; open(OUTFILE, ">outfile.txt") or die "Can't create outfile.txt: $!"; # ALWAYS check for errors when opening file handles. It's a good habit to get into.
print "Enter name of the Media file to analyse: "; # I'd keep the above on one line. Looks a little neater chomp($realname = <STDIN>); $counter = 0; # Add this while(<INFILE>) { if(/$realname/) { print OUTFILE; $counter++; # And add this } } # And finally do something with the new value of $counter print "$counter lines were saved to the output file\n"; HTH John -----Original Message----- From: Tim Lago [mailto:[EMAIL PROTECTED]] Sent: 19 February 2002 14:31 To: [EMAIL PROTECTED] Subject: How to count lines in an output file I've written a really simple script that opens a file, reads for specific line of text and copies the matches to an output file, Here it is: open(INFILE, "rmaccess1.txt"); open(OUTFILE, ">outfile.txt"); print "Enter the name of the Media file to analyze and press Enter: \n"; chomp($realname = <STDIN>); while(<INFILE>) { if(/$realname/) { print OUTFILE; } } Now, I want to add another line that counts the number of lines that were created in the outfile.txt, any help? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------Confidentiality--------------------------. This E-mail is confidential. It should not be read, copied, disclosed or used by any person other than the intended recipient. Unauthorised use, disclosure or copying by whatever medium is strictly prohibited and may be unlawful. If you have received this E-mail in error please contact the sender immediately and delete the E-mail from your system. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]