in reply to replacement of newlines
First of all, I can't even see how you managed to get this code to run. You've got C++ comments in there. Assuming this was a typo caused by sleep deprivation, we move on to the next issue:
use warnings;
use strict;
Had you done that, you'd have found that your output file wasn't open when you tried to write to it. This could have saved you some tearing out of hair. So use something like open(OUTFILE, ">", "outfile.txt");
Next we've got the regex. You were on the right track, but you were trying to do too much. All you needed for the newline marker was \n. However, there were a couple of other problems. The parentheses around the $1 would be added to your text; you need to eliminate them. Finally, the regex was slightly off. Basically, you wanted to capture any characters, up to the newline. If there was a period, you wanted to ignore that (not make the substitution), but you still needed to capture it. So you get:
$contents =~ s/(.*?[^\.])\n/$1/mg;I hope you're able to sleep now... but knowing programmers, you'll probably think to yourself, "just one more little change here...".
Update: [id://McDarren]'s regex is correct; mine lacks the double-quote, which would create problems with the second item.
|
|---|