Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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

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

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


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.


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 = '' . enurl($hashref);

    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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://355420]
erix considers extracting a catalog ...
[karlgoethebier]: marioroy: Racket ball is considered harmful, like Squash
[marioroy]: Wait till folks see what MCE::Hobo can do in the upcoming release. Multiple instances, nested spawning, 3 levels, doesn't matter. it works on Windiows too.
[Lady_Aleena]: I hate sites that tell me to turn ad-blocker off. They should know better.
[marioroy]: s/Windiows/ Windows/
[Discipulus]: marioroy can you expand that Niagara's fall history?
erix only sees fallen angels
erix if it weren't for bad luck, I'd have no luck at all
Discipulus Windiows the OS of native americans..
[karlgoethebier]: marioroy: Next step: Write the ultimate book. "Parallel Programming With Perl. Yet Another Missing Manual" ;-)

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (12)
As of 2017-05-29 08:46 GMT
Find Nodes?
    Voting Booth?