Hi Monks,

First of all, and this being my first post in the place, hi everyone.
Although I've definitely been relying on this site for some time now, this is the first question I ask (which, let me say, should speak well about the community).

Now, Im using LWP::UserAgent to download large XML files. Files do download successfully and their content is the expected, the problem is the high memory usage due to their size (>100MB).
To sort this out, I tried to rely on LWP::UserAgent 's "get" function option ":content_file".
Here's my code:

#!/usr/bin/env perl use strict; use warnings; use File::Temp; use LWP::UserAgent; #use HTTP::Request; do_task(); sub do_task { my $ua = LWP::UserAgent->new( 'ssl_opts' => { 'verify_hostname' => 0 } ); $ua->show_progress(1); my @urls = ( "http://linkToAFat.xml", ); foreach my $url ( @urls) { my ($fh, $path) = File::Temp::tempfile(DIR => '/tmp/my_tmp'); $ua->get($url, ":content_file" => $path); #my $request = HTTP::Request->new(GET => $url); #my $response = $ua->request($request, $path); } }
(Commented lines are additional ways I've tried to work the high mem usage around)

My problem is that, apparently, although I'm using the ":content_file" option, files' content DOES still get loaded into memory.

I am quite stuck with this one, so I'd appreciate Monks' almighty support.
Thanks in advance!


In reply to LWP::UserAgent & memory problems by Uree

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.