On Sat, 29 Mar 2003, Timothy Bolz wrote:
>I'm have a perl script which I want to make a web page and put it into a 
>specific directory.   And If I wanted to put some of the variables into the 
>page how would I do this?

There are several ways to get variables into your output:

     print 'The value of the variable is ', $variable;

or
     print "The value of the variable is $variable";

or

     print <<"EOD";
     The value of the variable is $variable
     EOD

It should be pretty obvious what's going on in the first case.  In the
second and third cases, the secret is that Perl will substitute the values
of variables inside double-quoted strings.  As the third case shows, it
even works with the "<<" syntax, provided you quote the end-of-data marker
with double quotes (when you put quotes around the end-of-data marker, Perl
pretends that the entire data block is quoted with the same kind of
quotation marks).

In addition to $variables, double quotes will also substitute @arrays (but
not %hashs), \escapes, and `backticked shell commands`.

>Now what if I want the page to called IP&ports.html how do I name it that and 
>then put it in a specific directory.  I did a shell scripts which did this 
>but I lost it, and Perl is different.  Would it be "EOM >>IP&ports.html" or 
>"ENDHTML >> IP&ports.html"?

No.  In Perl you have to open the file first, and specify the file
descriptor as the "indirect object" argument to the print command.

For example,

     open FILE, ">filename";

and then

     print FILE "Some text";     # note no comma after FILE

or

     print FILE <<"EOD";
     Some text
     EOD

When you're done printing to the file, it's a good idea to close it:

     close FILE;

(Perl will do that automatically for you when the script ends, but
sometimes it's good to make sure the file is closed before then.)

Note that the above example throws away whatever information was previously
in "filename".  To append to the end of the file instead of throwing away
the previous contents, use ">>" instead of ">":

     open FILE, ">>filename";

               - Neil Parker

_______________________________________________
Eug-LUG mailing list
[EMAIL PROTECTED]
http://mailman.efn.org/cgi-bin/listinfo/eug-lug

Reply via email to