in reply to Re: [Class Assignment] Regex and Output Files
in thread [Class Assignment] Regex and Output Files

Thank you, still new here so I was not aware. So I've gone through and made the changes you've suggested. However, nothing happens with my output.txt file once the code is executed.
use strict; use warnings; open(my $in, "<", "input.txt") or die "Cannot open < input.txt: $!"; open(my $out, ">", "output.txt") or die "Cannot open < output.txt: $!"; while(my $line = <$in>) { $line =~ s/new/old/i; print $out $line; }

Replies are listed 'Best First'.
Re^3: [Class Assignment] Regex and Output Files
by marinersk (Priest) on Feb 20, 2015 at 16:28 UTC

    I used your most recent code with this input.txt file:

    Out with the old, in with the new. Old stuff is cool. New stuff is also cool. Now to mess with your head: Fortune favors the bold. I knew it.

    It produced the following output.txt file:

    Out with the old, in with the old. Old stuff is cool. old stuff is also cool. Now to mess with your head: Fortune favors the bold. I kold it.

    Do you see the problem(s) yet?

    Hint:It is a useful skill to be able to fabricate good test data.

      I do see the problem, I adjusted my regex to fix this =~ s/\bnew\b/old/ig;. I was having problems with the output before, It's working fine now. Thank you for bringing this to my attention!

        You bet -- and congratulations!

        Also, thank you for having the courtesy to point out this was a class assignment. I have no doubts your integrity will serve you well in your life.

Re^3: [Class Assignment] Regex and Output Files
by toolic (Bishop) on Feb 20, 2015 at 15:47 UTC
    nothing happens with my output.txt file once the code is executed
    I don't know what that means. See also: http://sscce.org