in reply to Best way to generate URLs in CGI script?

The trick -- if you really want to use CGI.pm to do this -- is to override what CGI.pm believes the script name is, which can be done temporarily with local...

use CGI '-oldstyle_urls'; my $cgi1 = CGI->new; { local $ENV{'SCRIPT_NAME'} = '/graph'; my $cgi2 = CGI->new({ 'channel' => 1, 'size' => 400, 'ysize' => 300, }); print $cgi2->url( -query_string => 1 ), "\n"; } print $cgi1->url( -query_string => 1 ), "\n";

The only caveat is to be really careful with your scoping: put the wrong thing in the wrong place, and it prolly won't work the way you expect.

    --k.


Replies are listed 'Best First'.
Re: Re: Best way to generate URLs in CGI script?
by bikeNomad (Priest) on Jul 27, 2001 at 07:31 UTC
    Thanks...

    I wonder about the design of CGI.pm; what good is having the object-oriented interface if it's dealing mostly with global variables anyway? Sure, it doesn't have to export names into main::, but what's the point? The HTML generation stuff doesn't access any object state, so it's pointless as instance methods. The url escaping stuff, likewise. So what really needs to be instance methods? Just things dealing with the current (global) query. So why is the whole mess in a single class?

      The HTML stuff using object state is very helpful if you want to subclass it.

      Contrived example, but for instance, if you want to keep track of the number of cells in the previous row so you can colspan the current row without hard coding it. (For tables that can change dynamically, you can provide your own Tr Td methods to track this.

      -Lee

      "To be civilized is to deny one's nature."