ItsyBitsy has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys, My code:
my $bot = WWW::Mechanize->new(); $bot->agent_alias( 'Linux Mozilla' ); # Create a cookie jar for the login credentials $bot->cookie_jar( HTTP::Cookies->new( file + => "cookies.txt", autosave => 1, ignore_discard => 1, + ) );
What i want to know is how to get the value of the session id present in the cookie.txt file. Is there any specific function or do i have to open the file and read it and then substitute the values.Also when i add the header field, there is a field called cookie. What exactly do i substitute in that field.

Replies are listed 'Best First'.
Re: Getting the value of cookies in cookies.txt file.
by Anonymous Monk on May 18, 2012 at 09:55 UTC
    Just scan over the cookies in the object! HTTP::Cookies

    $bot->cookie_jar->scan(sub { print "Cookie key ", $_[1], "\n" })
      When i try the following code this is what it prints.
      Cookie key at-main Cookie key sess-at-main Cookie key session-id Cookie key session-id-time Cookie key session-token Cookie key ubid-main Cookie key x-main
      What i need is for it to print the value of ubid main and session id. How do i achieve this.
        Okay. I guess i figured it out. I had to replace 1 with 2.