ChuckularOne has asked for the wisdom of the Perl Monks concerning the following question:
I have been away from Perl for almost 2 years and now I find myself needing a quick, elegant solution for what should be a simple problem.
I have a file that comtains records delimited by crlf (0D0A). In this file there are extra crlf's. The extra ones are always followed by || (two pipes).
I am trying to replace the "\n||" with a simple "||".
Here's what I'm doing. It's not working.
Any help would be greatly appreciated.#! /usr/bin/perl $datafile=@ARGV[0]; my $data; { local($/) = undef; open (FILE, "<$datafile"); $data = <FILE>; close FILE; $data =~ s/\x0d\x0a\x7c\x7c/\x7c\x7c/sg; if ($data =~ m/\x0d\x0a\x7c\x7c/) { print "FOUND IT!\n"; } else { print "DIDN'T FIND IT.\n"; } open (OUTFILE, ">$datafile"); print OUTFILE $data, "-Damn"; close OUTFILE; }
-Chuckularone
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: A serch and replace question
by PERLscienceman (Curate) on Oct 31, 2003 at 16:46 UTC | |
by Anonymous Monk on Oct 31, 2003 at 19:17 UTC | |
Re: A serch and replace question
by Abigail-II (Bishop) on Oct 31, 2003 at 16:32 UTC | |
by benizi (Hermit) on Oct 31, 2003 at 18:27 UTC | |
by ChuckularOne (Prior) on Oct 31, 2003 at 19:23 UTC | |
Re: A serch and replace question
by inman (Curate) on Oct 31, 2003 at 16:41 UTC | |
Re: A search and replace question
by Roy Johnson (Monsignor) on Oct 31, 2003 at 17:32 UTC | |
by duff (Parson) on Oct 31, 2003 at 21:25 UTC | |
Re: A serch and replace question
by bart (Canon) on Nov 01, 2003 at 11:30 UTC | |
Re: A serch and replace question
by pizza_milkshake (Monk) on Nov 01, 2003 at 07:05 UTC |
Back to
Seekers of Perl Wisdom