in reply to HTML printing

Here's an approach: add a query string to your url that specifies which page to display. Something like:   http://my.server.com/multipage.pl?page=1 Then, in your perl script, you grab this value and use it to decide which page to display. The query string can be anything you want: "?display=CoolStuff" would work fine. Just make sure you don't include any spaces. (There's a way to do that but don't worry about it now.)

Two ways to get the query string value. You can get the whole query string with    my $qstr = $ENV{QUERY_STRING}; and then parse it yourself to get the page reference.

Better would be to

use CGI my $cgi = CGI::new() or die "Can't load new CGI"; my $page = $cgi->param('page');
Then, as before, branch to or select the routine to print the specific page. You can use heredocs or normal print statements, or a mixed combination of the two, whatever does the job.

In printing your various HTML pages, you can then include the <a....> links you need with the appropriate query strings for the other pages. Like this:    <a href="http://my.server.com/multipage.pl?page=2">Show page 2</a> You can also have subroutines to spit out portions of the HTML if you have repeated sections. And you can use conditionals to deliver pieces depending on whatever you want (username, requested page, etc.)

If you want more query string values in one url in order to do cool things, just separate them with '&'. Update: Which of course, you must write as &amp; (see next post -- thanks merlin).

I recommend you check out the CGI module. You may not feel you need it for this simple exercise, but this project would be a good way to get to know it for later. It is a powerful, versatile, and well-tested module.

Also, if you want to know more about what is being passed from your browser and is capturable by Perl, here is a page that may help you.

There is also some magic involving HTTP (not HTML) headers that you need to take care of. The CGI module can help with this. Or, at the very least, just be sure to    print "Content-type: text/html\n\n"; before anything else. (Note the double NewLine.)

If you need more than this to get you going, just re-post. Good luck.

dv

Replies are listed 'Best First'.
Re: Re: HTML printing
by merlyn (Sage) on Feb 17, 2001 at 08:41 UTC
    If you want more query string values in one url in order to do cool things, just separate them with '&'.
    Which of course, you must write as &amp;, so when you send out the html, it looks like this:
    <a href="http://my.server.com/multipage.pl?page=2&amp;book=3">Show pag +e 2 of book 3</a>
    Please don't make the same mistake the monestary makes, which forces the browser to error-correct all the links, sometimes in surprising ways.

    And someday, I'll lean on his vroom-ness to fix this, but so far I'm just waiting for him to be enlightened on his own. {grin}

    -- Randal L. Schwartz, Perl hacker

      With great respect and appreciation for Randal... and not a little trepidation, let me quote two bits of tested perl code that each print '&' into an HTML page without making use of the '&amp' entity.

      The first example prints the '&' as displayed, plain text.
      The second example prints the '&' inside an HTML tag:

      print "Let's show a query string: ?key1=one&key2=two\n"; print "<a href='$my_url?key1=one&key2=two'>Click here</a>\n";
      The HTML '&amp' entity does have its use. A prime example of which is the fact that I had to type '&amp;amp' to get the third word in the previous sentence to appear correctly!

      Update: This is bad advice!! Read the next post for the correction. (This post left in place so that Randal's next post will make sense.)

        Both of those generate invalid HTML when displayed in a browser, which a browser must error correct to understand that "&key2" is not an entity. Try your experiment with "key2" replaced with "copy" and you'll get copyright symbols all over the place.

        I stand by my first statement. Dumping HTML to the browser, whether in the body of the text, or in the parameter of a tag, must be properly entity-escaped, and if not, you are relying on the error-correction behavior of the browser to correct for your avoidable failure. Please don't, and please don't tell others to copy your mistake.

        -- Randal L. Schwartz, Perl hacker