in reply to Re^2: Split file, first 30 lines only
in thread Split file, first 30 lines only

Apologies. huck is correct, it's obviously the $line_count variable which should be tested rather than $line in this instance.

This will only stop it processing the whole file. If you don't want to download the whole file then that's a different matter entirely and would require use of a technique such as HTTP Ranges.

Replies are listed 'Best First'.
Re^4: Split file, first 30 lines only
by wrkrbeee (Scribe) on Mar 01, 2017 at 20:01 UTC
    Hi Hippo, your answer above states "If you don't want to download the whole file then that's a different matter entirely and would require use of a technique such as HTTP Ranges." I've tried to Google HTTP ranges but no luck. Any ideas where I get a sense of what have in mind? Nothing else seems to work (just trying to nab the few lines from web pages). Thanks!

      Ranges are documented in section 14.35 of the HTTP RFC. They allow an HTTP client to request only part (or parts) of the resource which would ordinarily be retrieved in full (or in server-chosen chunks) from the server.

      The RFC only mandates byte-count ranges so you should use that instead of lines in order to be portable. However if you are after the first 30 lines of a 50,000 line response then just pick a large enough byte range that you will likely retrieve at least your 30 lines and if fewer lines are returned you can issue subsequent requests until you have all the data you require.

        is not what :read_size_hint => $bytes of LWP::UserAgent is for?

        or in other words: is :read_size_hint the implementation of the HTTP ranges you are talking about?

        If i remember the hint word is there because there is no guarantee that the chunk retrieved will be exactly $bytes long: it is merely a hint, which LWP may disregard.

        Even with such recomendation i remember i read somewhere, the following example seems to demonstrate that data is retrieved exactly by chunks of desired length, even for bizarre values of $bytes

        Obviosly the last chunk will be of arbitrary lenght.

        thanks

        L*

        There are no rules, there are no thumbs..
        Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
        Thank hippo!!