Re: Line Endings

2013-02-26 Thread Brian Fraser
On Mon, Feb 25, 2013 at 2:38 PM, Brandon McCaig wrote: > On Sun, Feb 24, 2013 at 11:17:40PM -0300, Brian Fraser wrote: >> my $over = ''; >> while ( sysread( $fh, $over, 8192, length($over) ) ) { >> while ( $over =~ /\R/ ) { >> my $line = encode('UTF-8', substr($over, 0, $+[0], '')); > >

Re: Line Endings

2013-02-25 Thread Brandon McCaig
On Sun, Feb 24, 2013 at 11:17:40PM -0300, Brian Fraser wrote: > my $over = ''; > while ( sysread( $fh, $over, 8192, length($over) ) ) { > while ( $over =~ /\R/ ) { > my $line = encode('UTF-8', substr($over, 0, $+[0], '')); I think you meant decode. :) Decode input, encode output. The int

Re: Line Endings

2013-02-24 Thread *Shaji Kalidasan*
ft to you. What you do with it is your gift back to God. --- From: Tiago Hori To: *Shaji Kalidasan* Cc: "beginners@perl.org" Sent: Sunday, 24 February 2013 9:11 PM Subjec

Re: Line Endings

2013-02-24 Thread Brian Fraser
On Fri, Feb 22, 2013 at 3:08 PM, Tiago Hori wrote: > Hi All, > > One problem that often encounter is with line endings. I have to parse > several kinds of files routinely and often these are generated in excel and > therefore it is hard to anticipate which line ending I actually h

Re: Line Endings

2013-02-24 Thread Tiago Hori
do with it is your gift back to > God. > > --- > > > > From: Dr.Ruud > To: beginners@perl.org > Sent: Sunday, 24 February 2013 4:51 PM > Subject: Re: Line Endings > > On 2013

Re: Line Endings

2013-02-24 Thread John Delacour
On 22/02/2013 18:08, Tiago Hori wrote: What I was wondering is: is there any way to force perl to use other line ending characters, like MacOS C The script below will first read the file for 1000 characters and set the value of $/. You can then loop through the lines in the usual way. #!/

Re: Line Endings

2013-02-24 Thread *Shaji Kalidasan*
o God. --- From: Dr.Ruud To: beginners@perl.org Sent: Sunday, 24 February 2013 4:51 PM Subject: Re: Line Endings On 2013-02-23 01:51, *Shaji Kalidasan* wrote: > my $cr = $content =~ tr/\r/\r/;

Re: Line Endings

2013-02-24 Thread Dr.Ruud
On 2013-02-23 01:51, *Shaji Kalidasan* wrote: my $cr = $content =~ tr/\r/\r/; my $lf = $content =~ tr/\n/\n/; my $crlf = $content =~ s/\r\n/\r\n/g; See also 'perldoc -q count'. Alternatives: my $cr = $content =~ tr/\r//; my $lf = $content =~ tr/\n//; my $crlf =()= $content =~ /\r\n/g;

Re: Line Endings

2013-02-24 Thread Dr.Ruud
On 2013-02-23 00:50, Jim Gibson wrote: my $content = do { local $/; <$fh> }; Leaner written as: my $content; { local $/; $content= <$fh> } -- Ruud -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

Re: Line Endings

2013-02-22 Thread Tiago Hori
"Binary file"; > #Do Something > } > [/code] > > [output] >> ./demo.pl important01.txt > Mac >> ./demo.pl important02.txt > Unix/Linux >> ./demo.pl important03.txt > DOS/Windows >> ./demo&g

Re: Line Endings

2013-02-22 Thread *Shaji Kalidasan*
} else {     print "Binary file";     #Do Something }   [/code] [output] >./demo.pl important01.txt Mac >./demo.pl important02.txt Unix/Linux >./demo.pl important03.txt DOS/Windows >./demo>demo.pl eagle.jpg Binary file [/output] Note: The following file format is fed in

Re: Line Endings

2013-02-22 Thread Jim Gibson
On Feb 22, 2013, at 10:40 AM, Andy Bach wrote: > On Fri, Feb 22, 2013 at 12:08 PM, Tiago Hori wrote: > >> What I was wondering is: is there any way to force perl to use other line >> ending characters, like MacOS CR? >> Another approach is to read the entire file into a scalar and then split

Re: Line Endings

2013-02-22 Thread Andy Bach
On Fri, Feb 22, 2013 at 12:08 PM, Tiago Hori wrote: > What I was wondering is: is there any way to force perl to use other line > ending characters, like MacOS CR? > Perl's "magic" var "$/" or via "use English" $RS or $INPUT_RECORD_SEPARATOR (Larry's mnemonic "as in poetry or think a mad slashe

Line Endings

2013-02-22 Thread Tiago Hori
Hi All, One problem that often encounter is with line endings. I have to parse several kinds of files routinely and often these are generated in excel and therefore it is hard to anticipate which line ending I actually have. It seems to me that during while loops, if the line ending is not a LF

RE: Making a program more robust with regard to line endings

2008-09-23 Thread Stewart Anderson
> See `perldoc -f binmode` and search for ":crlf" > > [Stewart Anderson] Or provide your operators with a means that enforces the transfer in the mode you actually want it? Then you don't have to do any changes to your own code, as long as you can trust the transfer method. Info

Re: Making a program more robust with regard to line endings

2008-09-23 Thread Mr. Shawn H. Corey
On Tue, 2008-09-23 at 10:01 -0400, Zembower, Kevin wrote: > Can anyone suggest a better solution? See `perldoc -f binmode` and search for ":crlf" -- Just my 0.0002 million dollars worth, Shawn Linux is obsolete. -- Andrew Tanenbaum -- To unsubscribe, e-mail: [EMAIL PROTECTED] For addi

Re: Making a program more robust with regard to line endings

2008-09-23 Thread Raymond Wan
Hi Kevin, Zembower, Kevin wrote: I've written a program to process a text file. The input file is generated on a DOS computer and transferred to my Linux host. Most of the time, the operator remembers to transfer it BINARY and not ASCII, so that the DOS line endings are preserved. Ho

Making a program more robust with regard to line endings

2008-09-23 Thread Zembower, Kevin
I've written a program to process a text file. The input file is generated on a DOS computer and transferred to my Linux host. Most of the time, the operator remembers to transfer it BINARY and not ASCII, so that the DOS line endings are preserved. However, occasionally, they forget, an

Trouble with line endings

2006-02-12 Thread Rick Triplett
I shared this thread with the support people at Bare Bones Software. This was their reply: Hi Rick, TextWrangler always uses \r (ASCII 13, the canonical carriage return) internally, but you can tell it to use any desired representation on disk for the line endings: Mac (CR), Unix (LF), or

Re: Trouble with line endings

2006-02-10 Thread Xavier Noria
the latest OS (10.4.4). My text editor (Bare Bones TextWrangler) told me that the line endings in my file were \r (character 13) as I expected on a Mac. Wrong, Perl's "\n" in OS X is eq "\012". TextWrangler is known to save files using the old convention (and mo

Re: Trouble with line endings

2006-02-10 Thread Chas Owens
On 2/10/06, Rick Triplett <[EMAIL PROTECTED]> wrote: snip > My perplexities are these: Why did TextWrangler show \r for the line > endings after I had save them for Unix (\n)? And, why did Perl have > difficulty with the line endings in the first place? Perl is supposed > to b

Trouble with line endings

2006-02-10 Thread Rick Triplett
Bare Bones TextWrangler) told me that the line endings in my file were \r (character 13) as I expected on a Mac. However, when I slurped the file using the following code, the entire file was assigned to element 0 of the array: ... open FH, "<", "terms.txt"; @array = ; ch

Re: Autodetect line endings in a text file...

2002-05-29 Thread Todd Wade
"Sumit Babu" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Hello All, > > I will be getting the files from different platforms (i.e. Unix or > Windows). Is there a way i can automatically detect the line endings and

Re: Autodetect line endings in a text file...

2002-05-23 Thread drieux
On Thursday, May 23, 2002, at 08:37 , Timothy Johnson wrote: > Do you have to send the files back to their respective platforms? If not, > then I would suggest just changing all line endings to the line endings > that > your system uses. good point, and I think jonathan has also

RE: Autodetect line endings in a text file...

2002-05-23 Thread Timothy Johnson
Do you have to send the files back to their respective platforms? If not, then I would suggest just changing all line endings to the line endings that your system uses. -Original Message- From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: 5/23/02 5:21 AM Subject: Autodetect line

Re: Autodetect line endings in a text file...

2002-05-23 Thread Jonathan E. Paton
> I will be getting the files from different platforms > (i.e. Unix or Windows). Is there a way I can automatically > detect the line endings and accordingly use the chomp > function to remove it. You need to remember Mac's have Yet Another Newline Sequence, which makes t

Autodetect line endings in a text file...

2002-05-23 Thread Sumit_Babu
Hello All, I will be getting the files from different platforms (i.e. Unix or Windows). Is there a way i can automatically detect the line endings and accordingly use the chomp function to remove it. Regards, Sumit. <<<>>> <<<>>> <<<>>>