>>>>> "Dinos" == Dinos Liolios < dinos007%40yahoo.com">dinos007
yahoo.com> writes:
Dinos> Hello. I have written a search cgi script which has a
Dinos> lot of arguments with which you can search a database.
Dinos> Now a friend of mine wants to create a tree using
Dinos> hardcoded search URL from my site. The obvious URL is
Dinos> setting to all arguments to empty except the one he
Dinos> wants to search by. However the is an extremely long
Dinos> string. I was wondering if it is possible to type
Dinos> only the argument by which you are searching in the
Dinos> url.
Dinos> For example instead of:
Dinos> http://genomesonline.org/search.cgi?orgcol=org&domcol=dom&typecol=type&sizecol=size&infocol=info&datacol=data&instcol=inst&analycol=analy&contcol=contact&statuscol=status&goldstamp=ALL&gen_type=ALL&org_name1=genus&gensp=&org_domain=ARCHAEAL&org_status=ALL&size2=ALL&org_size=Kb&gen_gc=ALL&gen_seqmethod=ALL&gen_temperature=ALL&gen_ph=ALL&gen_symbiont=ALL&phylogeny2=ALL&gen_institution=ALL&gen_funding=ALL&gen_data=ALL&cont=ALL&gen_country=ALL&gen_pheno=ALL&gen_habitat=ALL&gen_disease=ALL&gen_relevance=ALL&gen_avail=ALL&selection=submit43;search
Dinos> I would like to have:
Dinos> http://genomesonline.org/search.cgi?org_domain=ARCHAEAL&selection=submit+search
Here's my code:
use URI;
my $uri = URI->new(<<'INLINE_TEXT');
http://genomesonline.org/search.cgi?orgcol=org&domcol=dom&typecol=type&sizecol=size&infocol=info&datacol=data&instcol=inst&analycol=analy&contcol=contact&statuscol=status&goldstamp=ALL
&gen_type=ALL&org_name1=genus&gensp=&org_domain=ARCHAEAL&org_status=ALL&size2=ALL&org_size=Kb&gen_gc=ALL&gen_seqmethod=ALL&gen_temperature=ALL&gen_ph=ALL&gen_symbiont=ALL&phylogeny2=ALL&gen_institution=ALL&gen_funding=ALL&gen_data=ALL&cont=ALL&gen_country=ALL&gen_pheno=ALL&gen_habitat=ALL&gen_disease=ALL&gen_relevance=ALL&gen_avail=ALL&selection=submit+search
INLINE_TEXT
my
query_form = $uri->query_form; # get the current params
my
new_query_form; # now select the elements we want
while (
query_form) {
my ($key, $value) = splice
query_form, 0, 2;
## select the items you want... not sure what your rule is here:
next unless defined $value and length $value; # skip empty values
next if $value eq 'ALL'; # skip "ALL"
push
new_query_form, $key, $value;
}
$uri->query_form(
new_query_form); # update the uri
print "$urin"; # and here it is:
The result is:
http://genomesonline.org/search.cgi?orgcol=org&domcol=dom&typecol=type&sizecol=size&infocol=info&datacol=data&instcol=inst&analycol=analy&contcol=contact&statuscol=status&org_name1=genus&org_domain=ARCHAEAL&org_size=Kb&selection=submit43;search
Again... I'm not sure how much of that you want to rip out. Maybe every
"default" value, but I don't know what your default values are. Just
add more steps to that "next" chain above... for example:
next if $key eq 'orgcol' and $value eq 'org';
would eliminate that item.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
< merlyn%40stonehenge.com">merlyn
stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!