in reply to Compare file content with a variable content

In
if ($modified = $string) { print "the file is the same";
you're assigning $string to $modified. To test wether they're equal, use the eq operator:
if ($modified eq $string) { print "the file is the same\n"; }
If you were to compare numbers, you'd use ==.


Update: The answer to your question is yes, even it's just one character, the two strings will mismatch.

ar0n ]

Replies are listed 'Best First'.
Re: (ar0n: use 'eq') Re: Compare file content with a variable content
by Skyhawlk (Initiate) on May 20, 2001 at 11:02 UTC
    I have tried both approches (either use 'eq' or just insert the scalar value of the string (array) into both vars and use '==' to compare between them, but the function always returns the "the file is not the same" printout no matter if both strings 'looks' the same. Could it be that there is a space character or CR somewhere in that file that causes to the mismatch?
      The string value was in fact surrounded by space characters so it was NOT the same as the other string. I have added some trimming:
      for ($modified_scalar) { s/^\s+//; s/\s+$//; }
      and it did the trick!