lwp::simple and rget--can I compare

B

bdy

I would like to print out the differences between the two variables
instead of just printing the varialbe again after it determines
someithing was added; I just want to print what was added. Any ideas?

#!/usr/bin/perl


use LWP::Simple;


$| = 1;
while (1) {
$firstcopy = $_;
$_ = get("http://www.google.com");


s/tagged.*\z//sm;
s/\A. *needtag. *?$//sm;
s/<[^>]+>//gm;
s/\n\n+/\n\n/gm;
if ($firstcopy ne $_) {
print ('', '', $_);



}


sleep 10;
 
B

bdy

Why do you think that you need to enable auto-flushing?


Where do you expect to exit this loop?


What, exactly, are you expecting the value of $firstcopy to be here?


Why have you supplied those particular first two arguments to print()?

I didn't see this reponse; I removed my other post.

Will answers to any of your questions help you answer this question:

Can I print the difference between two variables?

In this case, the difference between $_ =get("http://www.google.com")
and
$_ =firstcopy
 
B

bdy

It is bad manners to quote .sigs.

Have you seen thePostingGuidelinesthat are posted here frequently?



Yes. That is why I asked them.

Your code never puts anything into $_ before it copies it to
$firstcopy, so you might as well have

   $firstcopy = undef;
instead of
   $firstcopy = $_;

You should always enable warnings when developing Perl code.


If the get() succeeds then $_ will not contain undef, and will
probably also not contain the empty string, so

    $firstcopy ne $_

will be true every single time.

The code you posted made no sense at all.

My questions were an attempt to draw some sense from it.

If you post a short and complete program *that we can run*, then
we can surely help you solve your problem. If you don't, then
we probably can't.

Have you seen thePostingGuidelinesthat are posted here frequently?

--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"- Hide quoted text -

- Show quoted text -
If you post a short and complete program *that we can run*, then
we can surely help you solve your problem. If you don't, then
we probably can't.

OK, so my problem is that I don't have a run-able program; so I may be
better off explaining what I'd like to do and what I've constructed
thus far:

I would like to assign a variable the content of a URL via "get,";
have Perl commit that to memory; then wait for a determined amount of
time; get via "get" the content of the same URL as the one committed
to memory earlier, and then compare the old, memory-committed version
of the URL to the recently retrieved content.

What I have so far is a program commits the two instances of the
retrieved URL and compares them, but I can only print out the second
instance if they are different, not the difference itself.

I've also used File::Compare, but that doesn't yield any results;
perhaps I'm using it wrong; I'm running it from a command prompt on
Windows XP; the following is the program:

#!/usr/bin/perl


use LWP::Simple;
use File::Compare;


$| = 1;


$firstcopy = get("http://www.google.com");
sleep 10;
$secondcopy = get("http://www.google.com");


if ($firstcopy ne $secondcopy) {
print ('There has been a content change');



}
 
B

bdy

It is bad manners to quote .sigs.

Have you seen the Posting Guidelines that are posted here frequently?



Yes. That is why I asked them.

Your code never puts anything into $_ before it copies it to
$firstcopy, so you might as well have

   $firstcopy = undef;
instead of
   $firstcopy = $_;

You should always enable warnings when developing Perl code.


If the get() succeeds then $_ will not contain undef, and will
probably also not contain the empty string, so

    $firstcopy ne $_

will be true every single time.

The code you posted made no sense at all.

My questions were an attempt to draw some sense from it.

If you post a short and complete program *that we can run*, then
we can surely help you solve your problem. If you don't, then
we probably can't.

Have you seen the Posting Guidelines that are posted here frequently?

--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"- Hide quoted text -

- Show quoted text -
If you post a short and complete program *that we can run*, then
we can surely help you solve your problem. If you don't, then
we probably can't.

OK, so my problem is that I don't have a run-able program; so I may
be
better off explaining what I'd like to do and what I've constructed
thus far:


I would like to assign a variable the content of a URL via "get,";
have Perl commit that to memory; then wait for a determined amount of
time; get via "get" the content of the same URL as the one committed
to memory earlier, and then compare the old, memory-committed version
of the URL to the recently retrieved content.


What I have so far is a program commits the two instances of the
retrieved URL and compares them, but I can only print out the second
instance if they are different, not the difference itself.


I've also used File::Compare, but that doesn't yield any results;
perhaps I'm using it wrong; I'm running it from a command prompt on
Windows XP; the following is the program:


#!/usr/bin/perl


use LWP::Simple;
use File::Compare;


$| = 1;


$firstcopy = get("http://www.google.com");
sleep 10;
$secondcopy = get("http://www.google.com");


if ($firstcopy ne $secondcopy) {
print ('There has been a content change');

}
 
B

bdy

It is bad manners to quote .sigs.

Have you seen the Posting Guidelines that are posted here frequently?



Yes. That is why I asked them.

Your code never puts anything into $_ before it copies it to
$firstcopy, so you might as well have

   $firstcopy = undef;
instead of
   $firstcopy = $_;

You should always enable warnings when developing Perl code.


If the get() succeeds then $_ will not contain undef, and will
probably also not contain the empty string, so

    $firstcopy ne $_

will be true every single time.

The code you posted made no sense at all.

My questions were an attempt to draw some sense from it.

If you post a short and complete program *that we can run*, then
we can surely help you solve your problem. If you don't, then
we probably can't.

Have you seen the Posting Guidelines that are posted here frequently?

--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"- Hide quoted text -

- Show quoted text -
If you post a short and complete program *that we can run*, then
we can surely help you solve your problem. If you don't, then
we probably can't.

OK, so here's my code; I was able to run it on Windows XP from the
command prompt, call the .pl file:


#!/usr/bin/perl


use LWP::Simple;
use File::Compare;


$| = 1;


$firstcopy = get("http://www.google.com");
sleep 10;
$secondcopy = get("http://www.google.com");


if ($firstcopy ne $secondcopy) {
print ('There has been a content change');



}

It correctly recognizes a difference, if one exists; but I don't know
how to print that difference. I tried File:Compare as well; no
success; I didn't see any feature that would allow me to print the
difference between the two variables.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top