lwp::simple and rget--can I compare

Discussion in 'Perl Misc' started by bdy, Jul 30, 2009.

  1. bdy

    bdy Guest

    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;
    bdy, Jul 30, 2009
    #1
    1. Advertising

  2. bdy

    bdy Guest

    On Jul 29, 9:46 pm, Tad J McClellan <> wrote:
    > bdy <> 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
    bdy, Jul 30, 2009
    #2
    1. Advertising

  3. bdy

    bdy Guest

    On Jul 30, 10:55 am, Tad J McClellan <> wrote:
    > bdy <> wrote:
    > > On Jul 29, 9:46 pm, Tad J McClellan <> wrote:
    > >> bdy <> 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');



    }
    bdy, Aug 5, 2009
    #3
  4. bdy

    bdy Guest

    On Jul 30, 10:55 am, Tad J McClellan <> wrote:
    > bdy <> wrote:
    > > On Jul 29, 9:46 pm, Tad J McClellan <> wrote:
    > >> bdy <> 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');

    }
    bdy, Aug 5, 2009
    #4
  5. bdy

    bdy Guest

    On Jul 30, 10:55 am, Tad J McClellan <> wrote:
    > bdy <> wrote:
    > > On Jul 29, 9:46 pm, Tad J McClellan <> wrote:
    > >> bdy <> 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.
    bdy, Aug 5, 2009
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas =?ISO-8859-15?Q?G=F6tz?=

    LWP::Simple and utf8 problem

    Thomas =?ISO-8859-15?Q?G=F6tz?=, Apr 19, 2004, in forum: Perl
    Replies:
    0
    Views:
    714
    Thomas =?ISO-8859-15?Q?G=F6tz?=
    Apr 19, 2004
  2. reggie

    LWP::Simple and authentication

    reggie, Jul 30, 2003, in forum: Perl Misc
    Replies:
    6
    Views:
    142
    Gregory Toomey
    Aug 3, 2003
  3. Dan
    Replies:
    3
    Views:
    128
    Brian Wakem
    Aug 19, 2005
  4. Thomas Götz

    LWP::Simple and utf8 problem

    Thomas Götz, Apr 19, 2004, in forum: Perl Misc
    Replies:
    1
    Views:
    146
  5. Replies:
    3
    Views:
    195
    John Mason Jr
    Dec 18, 2004
Loading...

Share This Page