I would have probably used a different approach and not relied on the modified header from the server. For tasks like these, I'm in love with MD5 ...
#!/usr/bin/perl -w use strict; use MD5; use LWP::Simple; my $url='http://www.mrnick.binary9.net'; my $file='sitechanges.txt'; ## grab the contents my $content=get($url) || die $!; ## grab the MD5 sum from our datafile my $oldmd5=''; if (-f $file) { open(IN,"<$file") || die $!; $oldmd5=<IN>; close IN; } ## generate the new MD5 my $newmd5=MD5->hexhash($content); ## same? if ($newmd5 ne $oldmd5) { ## file has change ... do something ## .... (insert your mailing code here) ## then save the new md5 open(OUT,">$file") || die $!; print OUT $newmd5; close OUT; }
But to answer your question, change
if ($modified = $string) { print "the file is the same";
to
if ($modified eq $string) { print "the file is the same";

Update: The size of the files you are grabbing IS very important. 18MB is quite bit for casual downloading for comparison. In that case, I would also rely on the headers returned from HEAD (including Content-Length).


In reply to Re: Compare file content with a variable content by mr.nick
in thread Compare file content with a variable content by Skyhawlk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.