In loop wait for function return

Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default In loop wait for function return

    I would like to loop through a few URL's utilizing the LWP::Simple get function.
    Using the existing 'logic' ( or lack thereof ) is there a way to have the
    script wait before executing the next iteration of the for loop. At the moment
    the 'get' function does not have enough time to complete its' request.
    I looked into fork, wait, exec, etc but those don't seem to be what i'm looking
    for. I though 'eval' would do it but it doesn't. thanks


    #!/usr/bin/perl -w

    use strict;
    use diagnostics;
    use LWP::Simple;
    require HTML::TokeParser;

    my $url = 'http://localhost/page.html';
    my $url2 = 'http://localhost/page2.html';
    my $url3 = 'http://localhost/page3.html';
    my @urls = qq($url $url2 $url3);

    # yes, of course this works
    #die "LWP::Simple is empty: $! " unless ( parse_page(my $webPage = get($url)));

    # loop does not give LWP::Simple function get enough time to
    # return before looping, just dies

    for my $page (@urls) {
    die "cant get web page: $!\n" unless ( my $webPage = get($page));
    # eval does not die, exits with success but nothing sent to
    # function
    #eval {($webPage = get($page));}; die $@ if $@; # returns ok
    #eval {&parse_page($webPage = get($page));}; die $@ if $@; #return ok but
    # nothing send to function, script dies
    }


    sub parse_page {
    shift ,etc
    }
    mUs Guest

  2. Similar Questions and Discussions

    1. How to make function wait for HTTPService completion
      Dear group, I have a function that creates a new HTTPService(), sends the request and then creates a new ComboBox() intended to display the data...
    2. Wait function
      Is there any way that i can make my application wait for some time so that page loads in that time, right now I am using following code, ...
    3. Call to webservice doesn't wait to return
      Hi All, I have created a ASP.NET web service with a web method. This method retrives data from SQL Server and returns it as an XML string. Now...
    4. wait loop
      Hello, How do I pause my application for a given number of seconds without blocking any other application or user input? I've found the sleep...
    5. Function/Global var to return name of calling function?
      I'm sure I saw this somewhere but can't remember where and can't find it now... Is there a PHP function or global variable that will return name...
  3. #2

    Default Re: In loop wait for function return

    "mUs" <cmustard_!SPAM@nyc.rr.com> wrote in message
    news:X2dZa.111703$852.20426@twister.nyc.rr.com...
    > I would like to loop through a few URL's utilizing the LWP::Simple get
    function.
    > Using the existing 'logic' ( or lack thereof ) is there a way to have the
    > script wait before executing the next iteration of the for loop. At the
    moment
    > the 'get' function does not have enough time to complete its' request.
    > I looked into fork, wait, exec, etc but those don't seem to be what i'm
    looking
    > for. I though 'eval' would do it but it doesn't. thanks
    The get function returns a string, usually containing HTML. It generally
    takes 1-2 seconds to run for me.

    If you are saying that the web server at the other end takes a long time to
    return you request, or does not return at all, then maybe he URL is wrong or
    the web server is overoaded? Have you tried typing the URLs in a browser?

    Forking of subprocesses does not solve the underlying problem.

    gtoomey




    Gregory Toomey Guest

  4. #3

    Default Re: In loop wait for function return

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    mUs <cmustard_!SPAM@nyc.rr.com> wrote in
    news:X2dZa.111703$852.20426@twister.nyc.rr.com:
    > I would like to loop through a few URL's utilizing the LWP::Simple get
    > function. Using the existing 'logic' ( or lack thereof ) is there a
    > way to have the script wait before executing the next iteration of the
    > for loop. At the moment the 'get' function does not have enough time
    > to complete its' request. I looked into fork, wait, exec, etc but
    > those don't seem to be what i'm looking for. I though 'eval' would do
    > it but it doesn't. thanks
    The script *is* waiting for the 'get' to return before going on to the next
    iteration of the loop. What are you seeing (versus what you're expecting)
    that is causing you to think otherwise?

    - --
    Eric
    $_ = reverse sort $ /. r , qw p ekca lre uJ reh
    ts p , map $ _. $ " , qw e p h tona e and print

    -----BEGIN PGP SIGNATURE-----
    Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

    iQA/AwUBPzWdRGPeouIeTNHoEQJ+kACeK1PREMpNGus4MkEAcJc0rR 7pi6sAoONf
    MUsJJ+LnlbeQNSOZSZDbqpuQ
    =Ila7
    -----END PGP SIGNATURE-----
    Eric J. Roode Guest

  5. #4

    Default Re: In loop wait for function return

    Eric J. Roode wrote:
    >mUs <cmustard_!SPAM@nyc.rr.com> wrote in
    >news:X2dZa.111703$852.20426@twister.nyc.rr.com:
    >
    >> I would like to loop through a few URL's utilizing the LWP::Simple get
    >> function. Using the existing 'logic' ( or lack thereof ) is there a
    >> way to have the script wait before executing the next iteration of the
    >> for loop. At the moment the 'get' function does not have enough time
    >> to complete its' request.
    >The script *is* waiting for the 'get' to return before going on to the next
    >iteration of the loop. What are you seeing (versus what you're expecting)
    >that is causing you to think otherwise?
    To the OP: check the return status of the request. You won't be able to
    do that using get(), but getstore(), which will save the retrieved data
    as a file, will at least return the status code. If it's not 200,
    something went wrong. More elaborate scripts using LWP::UserAgent can
    return you the complete headers.

    --
    Bart.
    Bart Lateur Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139