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

Greetings Monks, I need to modify a program to output to a file instead of STDOUT. I have consulted
http://search.cpan.org/~gaas/libwww-perl-6.02/lib/LWP/UserAgent.pm
but still don't know what to do. The following script is a model provided by http://www.uniprot.org/faq/28 to convert one form of a protein ID to another, It outputs to the screen and I need it to go to a file:
use strict; use warnings; use LWP::UserAgent; my $base = 'http://www.uniprot.org'; my $tool = 'mapping'; my $params = { from => 'ACC', to => 'P_REFSEQ_AC', format => 'tab', query => 'P13368 P20806 Q9UM73 P97793 Q17192' }; my $agent = LWP::UserAgent->new; push @{$agent->requests_redirectable}, 'POST'; my $response = $agent->post("$base/$tool/", $params); while (my $wait = $response->header('Retry-After')) { print STDERR "Waiting ($wait)...\n"; sleep $wait; $response = $agent->get($response->base); } $response->is_success ? print $response->content : die 'Failed, got ' . $response->status_line . ' for ' . $response->request->uri . "\n";
Thanks,next time I'll do the tutorial on OOP. Chet

Replies are listed 'Best First'.
Re: LWP::UserAgent -output to file?
by GrandFather (Saint) on Mar 27, 2011 at 21:35 UTC
    ... my $outFileName = "..."; open my $outFile, '>', $outFileName or die "Failed opening $outFileNam +e: $!"; $response->is_success ? print SoutFile $response->content : ... close $outFile;

    See open.

    True laziness is hard work
      Hey Grandfather: It worked as you said, Thanks, Chet