PDA

View Full Version : a scripts wich prints a script to a *.cgi file



findftp
July 5th, 2001, 15:21
Hello,

I have a small problem (I guess). I have made a script that is able to write another script to disc and chmod it so that it is executable.
I don't want to read data from another file because the script that's being printed to file is requested 120,000 times a day
But when I print :

print "Content-type: text/html\n\n";

to the file, the printed file will look like:

print "Content-type: text/html

";

So I have to make filters that convert \n into \\n
I also think that when I print a @ into the script, the script will give an error.

Are there any filters out there in the world that convert all Perl command into the same command with a \ in front of it, so that it is being escaped?
If not, could somebody give me a list with special characters/commands that cannot be written into a script without escaping it?

Below the script that outputs another script (note the double escape at the line break behind Content-type:text/html):

#!/usr/bin/perl

open(TEST, ">test.cgi");
flock(TEST, 2);

print TEST <<"CGI code";
#!/usr/bin/perl
print "Content-type: text/html\\n\\n";
print "This is a very often accessed script";
CGI code

close(TEST);
chmod(0755, "./test.cgi");

print "Content-type: text/html\n\n";
print "<html><head><title></title></head><body>Script updated!</body></html>";

Thanks for any help,

Michiel

lucifer
July 5th, 2001, 18:18
you can escape any none alphanumeric\whitespace character in most languages I'm sure and it is itself.

ie \# becomes # even if # does nothing special, and so is #

there is a function in php which slashes things as needed, there may be one in perl too.

PHP

string quotemeta (string str)


Returns a version of str with a backslash character (\) before every character that is among these: . \\ + * ? [ ^ ] ( $ )

atlas
July 5th, 2001, 19:02
PHP stole Perl's function :)

It's quotemeta() in perl.

-mk

findftp
July 6th, 2001, 04:50
Thank you,

How do I use the command?
Does this command also escape linebreaks (\n) and @'s