Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

One liner to read all cookie key/vals into a Hash...

by smullis (Pilgrim)
on Nov 08, 2004 at 09:45 UTC ( #406013=snippet: print w/ replies, xml ) Need Help??

Description:

Easily put all cookies key / value pairs into a hash table.

While I am sure that for the majority of readers of this site the following my be trivial, obvious or just plain easy... There may be someone, somewhere for whom I could save 10 minutes...

my $cookie_name = "whatever the cookie name is....";
my %cookie_hash = (map { split /=/, $_ }  $q->cookie('$cookie_name'));
Comment on One liner to read all cookie key/vals into a Hash...
Download Code
Re: One liner to read all cookie key/vals into a Hash...
by Anonymous Monk on Nov 08, 2004 at 11:19 UTC
    What's $q?

      Aha...

      $q is my query object (I'm using CGI.pm in an OO style.)

      e.g

      # Set up Pragmas + external modules use strict; use warnings; use Data::Dumper; use CGI qw(:standard); my $q = new CGI; print $q->header; print "Hello World!\n"; my $cookie_name = "whatever you wanna call it"; my %cookie_hash = (map { split /=/, $_ } $q->cookie('$cookie_name')); +# print Dumper \%cookie_hash; print $q->end_html;

      Cheers

      SM

Back to Snippets Section

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2014-08-02 06:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (55 votes), past polls