For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > July 2006 > How to split a file on the CR carriage Return and/or replace









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to split a file on the CR carriage Return and/or replace
Steve Pittman

2006-07-26, 6:57 pm

I am using activestate on a windows box ...the files I am parsing are
Unix files...I tried this so far...

open ( IN, "<$_[0]" )||die "Can't open DAT source file: $tempFile
$!\n";
while (<IN> ){s/\r/\n/g;@lines = <IN>;}#
close (IN);

foreach $line (@lines)
{
Mumia W.

2006-07-26, 9:57 pm

On 07/26/2006 02:59 PM, Steve Pittman wrote:
> I am using activestate on a windows box ...the files I am parsing are
> Unix files...I tried this so far...
>
> open ( IN, "<$_[0]" )||die "Can't open DAT source file: $tempFile
> $!\n";
> while (<IN> ){s/\r/\n/g;@lines = <IN>;}#
> close (IN);
>
> foreach $line (@lines)
> {
>


Unix text files don't use \r in the line terminator. Under
Unix, \n by itself is the line terminator.


Joshua Colson

2006-07-28, 9:56 pm

On Fri, 2006-07-28 at 21:28 +0200, Dr.Ruud wrote:
> Robert Citek schreef:
>
>
> (spaces added for clarity)
>
> Is that different from the default?
> (see perlvar)


Using ActiveState on Windows it is.

--
Joshua Colson <jcolson@voidgate.org>

Joshua Colson

2006-07-28, 9:56 pm

On Fri, 2006-07-28 at 22:00 +0200, Xavier Noria wrote:
> That's wrong.
>
> $/ is eq "\n" everywhere, and "\n" has length 1 everywhere. "\n" is
> eq "\012" in all systems except MacOS pre-X where it is eq "\015". In
> particular "\n" is *not* CRLF on Windows.
>
> My article about newlines is moving forward at O'Reilly, I hope I can
> soon provide a pointer to it. Misconceptions about newlines arise too
> often, which was my main motivation to write it.


Thank you for the clarification. I stand corrected.

--
Joshua Colson <jcolson@voidgate.org>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com