Read remote text file line by line 
Author Message
 Read remote text file line by line

I'm using the below script to read a text file from a remote server.
Everything works great except I need the script to return the text
file line by line.

The length of each line in the file isn't fixed so I'm unable to use
4096 (or any other number).

Is it possible to get the script to return line by line?

Any help would be appreciated.

Thanks.

Jason Q.

========================================

#!/usr/bin/perl

require LWP::UserAgent;
$ua = new LWP::UserAgent;

$request = new HTTP::Request('GET', ' http://www.*-*-*.com/ ');

$response = $ua->request($request, \&callback, 4096);

sub callback
        {

        print "$data<P>";
        }



Wed, 18 Jun 1902 08:00:00 GMT  
 Read remote text file line by line

Quote:

> I'm using the below script to read a text file from a remote server.
> Everything works great except I need the script to return the text
> file line by line.

> The length of each line in the file isn't fixed so I'm unable to use
> 4096 (or any other number).

> Is it possible to get the script to return line by line?

> ========================================

> #!/usr/bin/perl

> require LWP::UserAgent;
> $ua = new LWP::UserAgent;

> $request = new HTTP::Request('GET', 'http://www.domain.com/file.txt');

> $response = $ua->request($request, \&callback, 4096);

> sub callback
>    {

>    print "$data<P>";
>    }

I would suggest dumping the call back and using $response->content
instead and then splitting that on whatever you consider to be your
line end characters? e.g. :

foreach $line ( split /\r?\n/,$response->content)
 {
   # do something with $line
 }

/J\
--
"Babylon 5 has some impressive special effects and enough dodgy hairdos
to make the current Conservative front bench look trendy" - Radio Times



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Search a file (line by line) for String/text

2. How do I read line by line of data from a file using perl

3. how to read a huge file line by line without loading it into memory

4. reading lines from one file and pulling matching lines in another

5. newbie perl question - reading a file line by line

6. Line by line file reading

7. How to read a file line by line w/loop

8. reading a file line by line backwards

9. Reading text file lines into an array

10. How to read one line from a text file

11. help reading multi-line text file

12. reading a txt file and inserting text lines in a HTML

 

 
Powered by phpBB® Forum Software