Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Pass arguments in URL

by kalyanrajsista (Scribe)
on Aug 23, 2010 at 14:13 UTC ( #856714=perlquestion: print w/replies, xml ) Need Help??
kalyanrajsista has asked for the wisdom of the Perl Monks concerning the following question:


I'm trying to prepare URL as below with lots of arguments. Is there any way that I can pass only one argument like using FreezeThaw Module by freezing all the parameters in form of hash and pass that reference in the URL. But it is printing some unnecessary characters in the URL. FYI, I'm using CGI Module


Replies are listed 'Best First'.
Re: Pass arguments in URL
by BrowserUk (Pope) on Aug 23, 2010 at 14:39 UTC

    Storable freeze produces a binary string that may contain a whole bunch of characters that would be incompatible with passing as part of a url. You might try url encoding the results of freeze, but I wouldn't like to rely upon that.

    It would be better to hexify the frozen data before adding it as a part of your url.

    Given oneScript like this:

    #! perl -slw use strict; use Storable qw[ freeze ]; my %params = ( period => 30, vid => 'xyz1234', person => 'homer', ); my $encoded = unpack 'H*', freeze \%params; system qq[ ?arg=$encoded];

    Calling another script like this:

    #! perl -slw use strict; use Data::Dump qw[ pp ]; use Storable qw[ thaw ]; my( $name, $payload ) = split '=', $ARGV[ 0 ]; my $params = thaw pack 'H*', $payload; pp $params;

    The result is:

    c:\test>oneScript { period => 30, person => "homer", vid => "xyz1234" }
Re: Pass arguments in URL
by ikegami (Pope) on Aug 23, 2010 at 14:50 UTC
    What freeze does is called serialising. You could serialise using Storable, but you didn't indicate any reason to do that.
    use URI qw( ); sub url_freeze { my ($base_url, @args) = @_; return URI->new($base_url, 'http')->query_form(@args); } my $url = url_freeze('/cgi-bin/details', %args);

    I may have the exact usage a bit off.

      Usage is more like this:
      use URI; use strict; use warnings; my $hostname = 'localhost'; my $path = '/cgi-bin/details'; my $period = 4; my $vid = 11; my $person = 'abcdef'; my @args = ( period => $period, vid => $vid, person => $person ); my $url = URI->new("http://$hostname/"); $url->path($path); $url->query_form( \@args ); print $url->canonical;
      The URI accessors do not support chaining.

      Update: I misread the parent as using chained accessors, which it wasn't, this is just a little more verbose than that
        You changed
        but both are ok. So that leaves the bad return value. Fixed:
        use URI qw( ); sub url_freeze { my $url = URI->new(shift, 'http'); $url->query_form(@_); return $url } my $url = url_freeze('/cgi-bin/details', %args);

        It won't freeze recursively, of course.

Re: Pass arguments in URL
by moritz (Cardinal) on Aug 23, 2010 at 14:22 UTC

    Please read How (Not) To Ask A Question, and then ask your question again, this time providing enough information for us to actually answer it.

    Perl 6 - links to (nearly) everything that is Perl 6.
Re: Pass arguments in URL
by Anonymous Monk on Aug 23, 2010 at 14:16 UTC
Re: Pass arguments in URL
by marto (Bishop) on Aug 23, 2010 at 14:46 UTC

    Like most others I'm confused by what you are trying to ask for. Are you looking for something like CGI::Session?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://856714]
Approved by moritz
[Corion]: ambrus: Yeah, I read that, but it's somewhat vague as in what I really have to implement, and where/how my "other" mainloop should/needs to call AnyEvent
[Corion]: (or maybe I just work better from existing code that I munge until it works and I understand it rather than a short abstract text like "implement everything that's needed" ;) )
[ambrus]: Corion: I think in this case you can get away with only a stub for idle, one that always dies when you create it, because AnyEvent::HTTP doesn't use it, not even indirectly through AnyEvent::Handle or AnyEvent::Socket or AnyEvent::DNS.
[Corion]: The "and I understand it" part is optional.
[Corion]: ambrus: Yes but I also need to implement the file / IO watcher, because Prima has that (in Prima::File), and I need to supply the appropriate thing to make push_write etc. work with Prima
[ambrus]: Corion: yes, you need to implement the io watcher, which should be simple because Prima::File is basically that, and the timer watcher form Prima::Timer
[Corion]: ... or so I think. As I said, I'm somewhat vague on how to make AnyEvent cooperate with a callback-driven IO event loop that gives me callbacks when data is available or can be written

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2016-12-08 12:15 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (141 votes). Check out past polls.