Forum Moderators: coopster & phranque

Message Too Old, No Replies

Writing to a file

         

mdharrold

1:57 pm on May 21, 2001 (gmt 0)

10+ Year Member



Is there an easier way to write many lines to a file without adding "print FILEHANDLE" to the start of each line?

I need to write about 3000 lines into two seperate files.

If it matters, it is 3000 lines of HTML with tables, links, and bookmarks.

theperlyking

2:09 pm on May 21, 2001 (gmt 0)

10+ Year Member



You dont need to start a new line for each print, i.e

print FILE "blah blah blah \n
more stuff here
and more <br>
etc..";

mdharrold

2:25 pm on May 21, 2001 (gmt 0)

10+ Year Member



Do I have to "\n" each end of the line? I put it up the way you suggested and it does not work. The error log is showing nothing.

theperlyking

2:36 pm on May 21, 2001 (gmt 0)

10+ Year Member



The \n will give you a line break in the source code, not needed except possibly to aid readability.

What do you mean by not work? Have you tried running the script from the command line to see the errors.
Also note that and " marks in the HTML will have to be escaped using \ unless you want to use ' marks.

Hope this helps:)

mdharrold

2:41 pm on May 21, 2001 (gmt 0)

10+ Year Member



It is hosted on a virtual domain. Is it still possible to run from the command line? I have escaped all ", &, @, %

Thanks for the help

theperlyking

2:45 pm on May 21, 2001 (gmt 0)

10+ Year Member



It should be, but you would need to telnet in to run it from the commandline - I often find it helps in diagnosing runtime problems.

Alternatively try a small script to test the principle :

#! /usr/bin/perl

print FILE "blah blah blah \n
more stuff here
and more <br>
etc..";

A tip, if you use ' marks you dont have to escape things - i.e

print FILE 'blah blah blah \n
more stuff here
and "blah"@@@ <br>
etc..';

will work fine.

mdharrold

3:09 pm on May 21, 2001 (gmt 0)

10+ Year Member



Well, that DID work fine.

Could there be a problem writing to the file using the $FORM{data}?

theperlyking

6:14 pm on May 21, 2001 (gmt 0)

10+ Year Member



I'm not too sure what value $FORM{data} holds in your case, is it a perl module you're using? If so I wonder if anyone else can provide some guidance as I tend not to use modules.

mdharrold

7:13 pm on May 21, 2001 (gmt 0)

10+ Year Member



By $FORM{data} I mean any FORM input. $FORM{*}