Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Data::Dumper and Cookies

by Perlbotics (Abbot)
on Jul 08, 2013 at 18:32 UTC ( #1043158=note: print w/ replies, xml ) Need Help??


in reply to Data::Dumper and Cookies

Data::Dumper is a good tool to visualise complex data structures, not to access them. In this case, you could access the JSESSIONID directly (since domain and path seem to be constant):

print $jar->{COOKIES}{'example.com'}{'/'}{'JSESSIONID'}[1], "\n";

But there is a better way. Since $mech->cookies() returns an HTTP::Cookies object, you should use its methods to access the cookie. The scan() method should accomplish what you want.

# ... as before, set $jar = ... sub callback { # 0 version # 1 key # 2 val # 3 path # 4 domain # 5 port # 6 path_spec # 7 secure # 8 expires # 9 discard # 10 hash #-- add more comparisons to narrow the search result print "Cookie: $_[2]\n" if $_[2] =~ /^8430/; } $jar->scan( \&callback );

See also perldsc, HTTP::Cookies, and maybe Data::Diver.


Comment on Re: Data::Dumper and Cookies
Select or Download Code
Re^2: Data::Dumper and Cookies
by PerlSufi (Pilgrim) on Jul 08, 2013 at 19:45 UTC
Re^2: Data::Dumper and Cookies
by sundialsvc4 (Abbot) on Jul 08, 2013 at 19:48 UTC

    That’s a key point.   (Up-voted!)   When the perldoc's tell you that a particular call returns an object, then that’s what you should work from:   treat it as an object, ask it questions, and dump the answers.   If you simply dump the object, it’s kinda like looking at an X-ray picture:   “yeah, that’s what the guts of the thing look like (ugh!), but that’s not really what I want to know.”   (You’d have to understand the deep-guts of the thing to understand what you are looking at, and who wants to stick their hands in guts when the thing is alive and can answer questions?)   Instead, call its methods, and dump what they tell you:

    print STDERR Data::Dumper->Dump( [ $myobject->foo(), $myobject->bar(), $myobject->bletch() ], [ 'foo says', 'bar says', 'bletch says' ] );

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2014-09-23 18:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (239 votes), past polls