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

Hi Monks

I have been trying to read some data from a web using LWP::UserAgent and this is what i have tried so far.

use Data::Dumper; require LWP::UserAgent; require HTTP::Request; my $request = HTTP::Request->new(GET => 'http://pilot/sanju/index.php/ +empdata'); my $ua = LWP::UserAgent->new; my $response = $ua->request($request); unless($response->is_success) { die 'Cannot connect to remote address' +; } my $cmd = $response->content; # print Dumper \$response; open (FILE, "<" , \$cmd ) or die $! ; while (<FILE>){ chomp; print $_; }
when i print using dumper (as per suggestions in CB)i am able to print the content but when itry to open using file handler it gives me an error as nosuch file or directory Can you please advise on how do i process on each line of $request. when i print $request using dumper it prints HTML format as below and i need to extract only the names can i have regex also please.
<td> 1 </td><td>engg </td><td> staff </td><td> ruslion,marry</td></ +tr> <tr> <td> 2 </td><td>accounts </td><td> operational </td><td> tom, +harry </td></tr> <tr><td> 3 </td><td>HR </td><td> support </td><td> john, +wirth

Replies are listed 'Best First'.
Re: Help on getting data from LWP::UserAgent
by pc88mxer (Vicar) on Jun 16, 2008 at 04:47 UTC

    Instead of parsing the HTML yourself, have a look at what HTML::TableExtract can do for you.

      Hi pc88mxer <c> Thanks a lot for your time and advise I could do this easily using HTML::TableExtract.
Re: Help on getting data from LWP::UserAgent
by CountZero (Bishop) on Jun 16, 2008 at 05:21 UTC
    When running your script against http://www.perlmonks.org it works as expected.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      Hi
      Thanks for you time. I tried the same code against against http://www.perlmonks.org and fac +ing the same error as no such file or directory.
        What version of Perl are you using?
        >c:\progs\perl561\bin\perl -e"open(my $fh, '<', \$buf) or die $!" No such file or directory at -e line 1. >c:\progs\perl580\bin\perl -e"open(my $fh, '<', \$buf) or die $!"

        Scalars as files is a 5.8 addition. In previous version, it would try to open a file called something like "SCALAR(0x225300)".

        PS - Please avoid placing your entire post in code tags. Start paragraphs with <p> instead.