Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display line by line - desperate

Status
Not open for further replies.
Apr 13, 2006
9
GB
Hey again,

ive got one more thing i desperatly need help with. I want to read a txt file and output it line by line. ive looked all over the net and read lord knows how many tutorials but i cant do it :'(..im stupid hehe.

this writes to the file:

&send_error("We were unable to write to the file.") unless (open GFILE, ">>$config{'basepath'}/games/games.txt");

print GFILE "$form{'GAMETITLE'}\n";
close GFILE;

I use the "\n" to print the info into the txt file line by line.

This is what i use to output it:

my $gamelist;
open(GFILE,"<$config{'basepath'}/games/games.txt");
($gamelist) = <GFILE>;
chomp($gamelist);
close(GFILE);

I need the code above to read to txt file line by line but i cant do it, can someone write it for me so it does this?? pwetty pwease :).

if I dont use the "\n" when printing to the file it works great but i want it to print line by line so its easier to find data and remove it. its just the output im having major problems with.
 
Try this:

Code:
open(GFILE,"<$config{'basepath'}/games/games.txt");
while(<GFILE>) { print }
close(GFILE);
 
ive looked all over the net and read lord knows how many tutorials but i cant do it

A google search for "perl print file" returns 27,000,000 hits, I'm sure a few of those will show how to open and print a file to stdout. The first page I opened has this:

Code:
Here is the basic perl program which does the same as the UNIX cat command on a certain file.

#!/usr/local/bin/perl
#
# Program to open the password file, read it in,
# print it, and close it again.

$file = '/etc/passwd';		# Name the file
open(INFO, $file);		# Open the file
@lines = <INFO>;		# Read it into an array
close(INFO);			# Close the file
print @lines;			# Print the array


although kordaff gave you a better suggestion if you just need to print the file to stdout and do nothing else with the data in the file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top