in reply to Switching out text only in a variable

How is you html search form written? The client should be providing the search term from user input, and it doesn't know anything about your $_query variable.

The cgi-lib library is very old now. It won't cope with new-fangled standards like ';' between query terms. You'd do well to replace with CGI.pm, which has some cgi-lib compatibility functions if you don't want to do a lot of rewriting.

Your substitution looks ok to me. You may want to split up the search text on spaces and do your substitution as an alternation of intividual search terms.

After Compline,
Zaxo

  • Comment on Re: Switching out text only in a variable

Replies are listed 'Best First'.
Re^2: Switching out text only in a variable
by powerhouse (Friar) on Nov 19, 2004 at 05:48 UTC
    Sorry, I guess I should have showed you the headers...

    I am using CGI.pm:  use CGI qw(:standard :cgi-lib escapeHTML);
    I guess I could just have the part where it prints the html link instead of putting &q=$_query I _could_ put a placeholder like &q={{replace_query}} then _after_ I Have it replace all the text then replace that with the original query. That just seems like a 'broken' way to do it. What do you think?

    thx,
    Richard

      Use CGI's html generation methods.

      # Assuming $q is from CGI->new my $url = $q->My::CGI::hypothetical_param( search => 'value' )->self_u +rl; sub My::CGI::hypothetical_param { my $current_q = shift; my $q = CGI->new( $current_q ); my $params = { @_ }; while ( my ( $param, $value ) = each %$params ) { if ( not defined $value ) { $q->delete ( $param ); } else { $q->param( $value ); } } $q; }