in reply to Re: Newbie: uses/limits of perl in editing files
in thread Newbie: uses/limits of perl in editing files

That's it! Wow, let's see how I go at adjusting it all for everything else I have to do to it. The weekend shall be fun.

One problem though, and I guess it has something to do with the \n point you made at the end. Now I have <cr> appearing at the end of every line. I'm sitting on a Linux workstation running RedHat if that is at all helpful (I DID say I know nothing about this!)

cheers
wherethewild

  • Comment on Re^2: Newbie: uses/limits of perl in editing files

Replies are listed 'Best First'.
Re^3: Newbie: uses/limits of perl in editing files
by Sixtease (Friar) on Nov 23, 2007 at 14:32 UTC

    Here's my guess:

    Your file has Windows newlines (cr/lf), which your editor/viewer can deal with and shows it correctly. Then you add unix newlines (lf) on the lines you edit. Now there are mixed cr/lf and lf newlines, which confuses the editor and it shows the cr characters.

    If I'm correct, then I recommend either preprocess the file with the dos2unix tool or address this in the perl script itself

    update: The modified while loop could look like this:

    while (my $line = <$rfh>) { chomp $line; if ($line =~ m/^HEADER/) { my $number = 42; # change to whatever number you want to use $line .= $number; } if ($line =~ m/^REMARK/) { print {$wfh} "Extra line\n" # Change to whatever extra line yo +u want } print {$wfh} $line, "\n"; }
      unfortunately, still a problem. Thanks for all the help so far though, it's certainly moving me forward much faster than if I was left to beat my head against the screen alone!