in reply to [Class Assignment] Regex and Output Files

UDPATE: Always mention that you cross-posted on another site (SO) and provide the URL.

Replies are listed 'Best First'.
Re^2: [Class Assignment] Regex and Output Files
by Hayest (Acolyte) on Feb 20, 2015 at 15:43 UTC
    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; }

      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!
      nothing happens with my output.txt file once the code is executed
      I don't know what that means. See also: http://sscce.org