in reply to Why does my Perl regex substitution for linebreak fail?
Anyway, I think others have already given good ideas. Here's another one, that doesn't require holding the entire file in memory at once (unless of course the file does not actually contain any instance of "\n===="):
Setting the INPUT_RECORD_SEPARATOR ($/, see perlvar) like that makes things very simple. If the file happens to have CRLF line termination, you may need to#!/usr/bin/perl use strict; use warnings; $/ = "\n===="; while (<>) { s/\n====$/====/; print; }
(updated upon realizing that a CRLF file would just need a modified s///; the original $/ setting above would still work fine -- oops! I just noticed that ikegami already posted this idea, as I should have known he would!)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Why does my Perl regex substitution for linebreak fail?
by pat_mc (Pilgrim) on Mar 06, 2008 at 09:15 UTC | |
by graff (Chancellor) on Mar 07, 2008 at 02:03 UTC |