in reply to Comparing $_ --- before/after

Instead of slurping the file into a scalar, read it to an array, and then do the substitutions one line at a time, printing as you go if you succeed at substituting on the line. I'm loath to attempt to code it since I should have been in bed quite a while ago, but in general if you want line-by-line action and control on a file, you shouldn't put it in a scalar.

Replies are listed 'Best First'.
Re^2: Comparing $_ --- before/after
by mrc (Sexton) on Oct 10, 2009 at 08:53 UTC
    Ok, let's simplify this.
    $string1 = "abcdf"; $string2 = "abcde"; #how to display difference between $string2 and $string1? $difference = "f";

      I'm not sure what do you call "difference". Can you give more strict definition? What is the difference between "Lazy dog" and "Loony owl"?

        Yes, true. I don't need all that code from String::Diff.
        I only want a simple way to display characters from second string which doesn't match to the characters in the first string.
        Yes. In your example, script should display
        $difference = "oony owl";
        as only starting "L" match both strings.