Re: question about WWW::Mechanize and grep

2010-09-04 Thread Gabor Szabo
Hi,

2010/9/4 ashar rizqi :
> Hi All
>
> I am trying to get to a webpage, look for matches of prices, print those
> matches to a file and send that file to excel where a chart is automatically
> generated. I dont have a problem with sending it to excel or getting to the
> webpage. I cant get it to match all the prices on the page and send all
> those matches to a file. I am using strawberry perl. I can do this in linux
> but linux doesnt have excel and theres nothing available to automate
> openoffice spreadsheet. Here is the closest I could get to it:
>

Actually you could use
http://search.cpan.org/dist/Spreadsheet-WriteExcel/
to create an Excel file on Linux as well
and I guess there are similar modules to generate
Open Office Calc documents.

Regarding your code. There is a bug that you are using $ witout
escaping it. This causes perl to think you are actually trying to use
the strange but valid $'

You could have find out about this bug if you were using

use strict;
use warnings;

at the beginning of your code as it would give you a warning:

Use of uninitialized value $' in regexp compilation at a.pl line 5.

that would have triggered your suspition.

I'd recommend that you start doing that.

You could use WWW::Mechanize but for a simple get request
I'd recommend using LWP::Simple and you don't need to save the
received content to a file, you can go over its lines while in memory;

use strict;
use warnings;

use LWP::Simple qw(get);
my $content = get( "http://austin.craigslist.org/apa/"; );
my @lines = split /\n/, $content;

open (my $OUT, ">", "list.txt") or die;
foreach my $line (@lines) {
   if  ($line =~ /'\$'[0-9].*/) {
 print $OUT $line;
  }
}

regards
   Gabor

-- 
Gabor Szabo
http://szabgab.com/
___
Perl-Win32-Web mailing list
Perl-Win32-Web@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


question about WWW::Mechanize and grep

2010-09-04 Thread ashar rizqi
Hi All

I am trying to get to a webpage, look for matches of prices, print those
matches to a file and send that file to excel where a chart is automatically
generated. I dont have a problem with sending it to excel or getting to the
webpage. I cant get it to match all the prices on the page and send all
those matches to a file. I am using strawberry perl. I can do this in linux
but linux doesnt have excel and theres nothing available to automate
openoffice spreadsheet. Here is the closest I could get to it:

use WWW::Mechanize;



  my $mech = WWW::Mechanize->new( autocheck => 1 );
  $mech->get( "http://austin.craigslist.org/apa/"; );


open(FD, ">> abc.txt") or die("Couldn't open test.dat\n");
print FD $mech->content;
close(FD);


open (FILE,"<","abc.txt");

open (OUT, ">","list.txt");

while(){

print OUT if(/'$'[0-9].*/);

}

close FILE;

close OUT;


The ouput doesnt match all the prices and it doesnt show only the price.
What am I doing wrong? In linux I just pipe the output to grep which gives
me the perfect response. Why won't this work?

Thank you in advance all help is much appreciated.
___
Perl-Win32-Web mailing list
Perl-Win32-Web@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs