Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LWP::Simple Module (Check content or die)

Status
Not open for further replies.

sdslrn123

Technical User
Jan 17, 2006
78
0
0
GB
Code:
use LWP::Simple;
open (HELLO, ">>thanks.txt");
foreach $person (@group) {
my $url = "http:domain/$person.txt";
my $content = get $url;
print HELLO $content;

@group contains list of names.

Hi there. The file from the website contains lots of details but I am just interested in the line that starts off with the word "Hobbies" and in particular those lines that contain the word football. I have tried using an if statement with regular expressions but the outfile just seems to be blank. I usually use this place as last resort (not because there is anything wrong with it!) but because I do know I should try, try, and try again but I just seem to have hit a brick wall with this one.

Any help is much appreciated.
Thanks
 

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
The website is my personal one which I just use to practice perl on thus the invented website name. Any help is much appreciated.
 
Paul's point is that it's not a valid URL. You're missing the two forward-slashes after "http:
 
Code:
use LWP::Simple;
open (HELLO, ">>thanks.txt");
foreach $person (@group) {
my $url = "[URL unfurl="true"]http://www.domain.com/$person.txt";[/URL]
my $content = get $url;
print HELLO $content;

Sorry, I was just typing fast.
Original problem still exists.
 
You're sure the txt files exist, and they're not .htm files?

Code:
use LWP::Simple;
open (HELLO, ">>thanks.txt");
@group=('index');
foreach $person (@group) {
  my $url = "[URL unfurl="true"]http://shuttle/a/$person.[/URL][COLOR=red]php[/color]";
  my $content = get $url;
  print HELLO $content;
}
close HELLO;
shuttle is just a machine on my desk here

There was a simple typo about no closing brace, but I assume you got that sorted. you can syntax check your programs by running
Code:
perl -c script.pl

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Hi

I feel bad as everyone is helping but... I'll just rephrase original query. How do I remove lines within a text file containing lines starting with the word "hobbies" and those hobby lines containing football into another text file using LWP::Simple module

Thanks again
 
use the code above to pull in the pages in, and then process each string line by line
Code:
use LWP::Simple;
open (HELLO, ">>thanks.txt");
open (FOOTY, ">>football.txt");
@group=('index');
foreach $person (@group) {
  my $url = "[URL unfurl="true"]http://shuttle/a/$person.php";[/URL]
  my $content = get $url;
  @lines=split /\n/, $content;
  foreach (@lines) {
    if (/^hobbies/) { #if hobbies is at the start of the line ignore
    } else {
       print HELLO $_."\n";
    }
    if (/football/) { #if line contains 'football', write it to the FOOTY file
       print FOOTY $_."\n";
    }
  }
}
close HELLO;
close FOOTY;

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top