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

Hi
Can someone please tell me what this kind of data structure this is:

my $reqs = [ HTTP::Request->new('GET', $selected_domains[0]), HTTP::Request->new('GET', $selected_domains[1]), HTTP::Request->new('GET', $selected_domains[2]), HTTP::Request->new('GET', $selected_domains[3]), HTTP::Request->new('GET', $selected_domains[4]), ];

Many thanks,
Tom

Title edit by tye (no one-word titles, please)

Replies are listed 'Best First'.
Re: Structure
by Tomte (Priest) on Mar 10, 2003 at 11:18 UTC

    [] constructs array-refs
    So you're dealing with $reqs as a reference to an array holding references to HTTP::Request-objects.

    see perldoc perlref and perldoc HTTP::Request

    regards,
    tomte


Re: Structure
by robartes (Priest) on Mar 10, 2003 at 11:19 UTC
    $reqs is a reference to an anonymous array containing freshly made HTTP::Request objects. To do something with one of them, you would do something like:
    my $index=2; print "URL of request no. $index is: ".$reqs->[$index]->url();

    CU
    Robartes-

      Ok cool thanks for that, so what if I add this code

      foreach my $req (@$reqs) { print "Registering '".$req->url."'\n"; if ( my $res = $pua->register ($req) ) { print STDERR $res->error_as_HTML; } } $entries = $pua->wait(); foreach (keys %$entries) { my $res = $entries->{$_}->response; }

      Can someone explain to me what the %entries is all about...?

      I want to loop through the above code lots and lots of time, but I need to clear out the entries hash after each run, how can I do this...?

      undef %entries # or %entries=();

      Doesn't seem to work for me

      Thanks again,
      Tom

        Can someone explain to me what the %entries is all about...?
        There is no hash %entries. There's only a scalar variable named $entries that seems to get back a hashreference as a result of the call $pua->wait() (whatever that is??). Read up on the differences between references and normal data types, e.g. in perldoc perlreftut or the same here online.

        When you say that you want to loop through the above code, what do you mean with above code? All of it? Because I see no reason why you should then need to clear out entries, you are getting back a new one every time out of $pua->wait() ...

        -- Hofmator