Gossamer Forum
Home : General : Perl Programming :

Printing Code

Quote Reply
Printing Code
How can I print my code in a txt file to a cgi?

I'd do it line by line but There are over 1,400 lines of code, and I can't do that line by line.

I tried print qq~~; but I didn't even think that would work, and it didn't. I though maybe printf qq~~; but nope.

Anybody done this before?

Thanks,

perlkid

Quote Reply
Re: Printing Code In reply to
Clarify please. You have 1400 lines of code in a txt file that you want to have a cgi program print?

Code:
open (MYFILE, 'file.txt') or die $!;
print while <MYFILE>;
close (MYFILE) or die $!;


Installation support is provided via ICQ at UIN# 53788453. I will only respond on that number.
Quote Reply
Re: Printing Code In reply to
 
Sorry Mate,

I want to open the txt file and print the contents to another cgi.

Script A opens code.txt and prints code after preforming one regex on it and then prints to Script B.

The usual way

open(file, "<code.txt");
@all=<file>;
close(file);
$file = @all;
$file =~ s!%%name%%!a!g;
open(data, ">script.cgi");
print data "$file";
close(data);

Doesn't work.

Thanks Mark,

perlkid

Quote Reply
Re: Printing Code In reply to
$file = @all returns the size of the array. Instead:

$file=<file>;

Also, add error handling when opening files.


Dan


Quote Reply
Re: Printing Code In reply to
Code:
open (INPUT, 'code.txt') or die "Can't open input file: $!";
open (OUTPUT, '>script.cgi') or die "Can't open output file: $!";
while (<INPUT>) {
s/%%name%%/a/g;
print OUTPUT;
}
close (OUTPUT) or die "Can't close output file: $!";
close (INPUT) or die "Can't close input file: $!";
--mark

Installation support is provided via ICQ at UIN# 53788453. I will only respond on that number.