Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > lwp::simple and rget--can I compare

Reply
Thread Tools

lwp::simple and rget--can I compare

 
 
bdy
Guest
Posts: n/a
 
      07-30-2009
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;
 
Reply With Quote
 
 
 
 
bdy
Guest
Posts: n/a
 
      07-30-2009
On Jul 29, 9:46*pm, Tad J McClellan <ta...@seesig.invalid> wrote:
> bdy <bdy120...@gmail.com> wrote:
> > 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;

>
> Why do you think that you need to enable auto-flushing?
>
> > while (1) {

>
> Where do you expect to exit this loop?
>
> > $firstcopy = $_;

>
> What, exactly, are you expecting the value of $firstcopy to be here?
>
> > print ('', '', $_);

>
> Why have you supplied those particular first two arguments to print()?
>
> --
> Tad McClellan
> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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


 
Reply With Quote
 
 
 
 
bdy
Guest
Posts: n/a
 
      08-05-2009
On Jul 30, 10:55*am, Tad J McClellan <ta...@seesig.invalid> wrote:
> bdy <bdy120...@gmail.com> wrote:
> > On Jul 29, 9:46*pm, Tad J McClellan <ta...@seesig.invalid> wrote:
> >> bdy <bdy120...@gmail.com> wrote:
> >> > 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;

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

>
> >> > while (1) {

>
> >> Where do you expect to exit this loop?

>
> >> > $firstcopy = $_;

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

>
> >> > print ('', '', $_);

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

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

>
> It is bad manners to quote .sigs.
>
> Have you seen thePostingGuidelinesthat are posted here frequently?
>
> > Will answers to any of your questions help you answer this question:

>
> > Can I print the difference between two variables?

>
> 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.
>
> > In this case, the difference between $_ =get("http://www.google.com")
> > and

>
> 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');



}



 
Reply With Quote
 
bdy
Guest
Posts: n/a
 
      08-05-2009
On Jul 30, 10:55*am, Tad J McClellan <ta...@seesig.invalid> wrote:
> bdy <bdy120...@gmail.com> wrote:
> > On Jul 29, 9:46*pm, Tad J McClellan <ta...@seesig.invalid> wrote:
> >> bdy <bdy120...@gmail.com> wrote:
> >> > 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;

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

>
> >> > while (1) {

>
> >> Where do you expect to exit this loop?

>
> >> > $firstcopy = $_;

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

>
> >> > print ('', '', $_);

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

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

>
> It is bad manners to quote .sigs.
>
> Have you seen the Posting Guidelines that are posted here frequently?
>
> > Will answers to any of your questions help you answer this question:

>
> > Can I print the difference between two variables?

>
> 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.
>
> > In this case, the difference between $_ =get("http://www.google.com")
> > and

>
> 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');

}
 
Reply With Quote
 
bdy
Guest
Posts: n/a
 
      08-05-2009
On Jul 30, 10:55*am, Tad J McClellan <ta...@seesig.invalid> wrote:
> bdy <bdy120...@gmail.com> wrote:
> > On Jul 29, 9:46*pm, Tad J McClellan <ta...@seesig.invalid> wrote:
> >> bdy <bdy120...@gmail.com> wrote:
> >> > 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;

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

>
> >> > while (1) {

>
> >> Where do you expect to exit this loop?

>
> >> > $firstcopy = $_;

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

>
> >> > print ('', '', $_);

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

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

>
> It is bad manners to quote .sigs.
>
> Have you seen the Posting Guidelines that are posted here frequently?
>
> > Will answers to any of your questions help you answer this question:

>
> > Can I print the difference between two variables?

>
> 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.
>
> > In this case, the difference between $_ =get("http://www.google.com")
> > and

>
> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
compare mdf for success restore of data and file storage =?Utf-8?B?UmFt?= ASP .Net 1 10-21-2005 03:12 AM
Trying to get C++ to get a file and compare for logon and password validation armandotop C++ 2 04-13-2005 05:48 PM
how to compare current date to a future date and validate it in ASP.NET James P. ASP .Net 7 07-13-2004 10:13 PM
How do you compare local and remote versions of a file? aualias ASP .Net 3 06-04-2004 02:20 PM
Looking For a tool to crawl ASP and compare to a folder of files to see which are used and which are not. Steve Mauldin ASP General 0 02-06-2004 04:15 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57