Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: How do I shorten/encode huge GET strings?

by Wonko the sane (Deacon)
on May 21, 2004 at 18:33 UTC ( [id://355420]=note: print w/replies, xml ) Need Help??


in reply to How do I shorten/encode huge GET strings?

Hello,

I am not sure what you mean by shortening the GET string. If you have alot of data, a POST may be better suited.

This is what I usually do when I need to encode a hash of data to use in a GET request though.

sub _url_encode_data { my ( $data ) = @_; my $post_string; foreach my $field ( keys %$data ) { next if ( $data->{$field} eq '' ); $data->{$field} =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",or +d($1))/eg; $post_string .= "$field=$data->{$field}&"; } return $post_string; } # END _url_encode_data
There may be a better way to do this(of course).

Hope that helps though.

Wonko

Replies are listed 'Best First'.
Re: Re: How do I shorten/encode huge GET strings?
by Jenda (Abbot) on May 22, 2004 at 20:50 UTC

    There are several wheels for this on CPAN already

    use CGI::Enurl; $url = 'script.pl?' . enurl($hashref);

    Jenda
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
       -- Rick Osborne

    Edit by castaway: Closed small tag in signature

Re: Re: How do I shorten/encode huge GET strings?
by kleinbiker7 (Sexton) on May 21, 2004 at 19:18 UTC
    Cheers Wonko...I will try that... By the way, how do you decode that string after you passed it to the server? Thanks!
      use the URI package.
      It will allow you to easily break apart (or assemble) any url including the query form with all special character sequences converted.
Re: Re: How do I shorten/encode huge GET strings?
by Anonymous Monk on May 22, 2004 at 03:26 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://355420]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2024-03-28 21:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found