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 have. It > seems t

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
ji > ----------- > Your talent is God's gift to you. What you do with it is your gift back to > God. > --- > > > - Orig

Re: Line Endings

2013-02-22 Thread *Shaji Kalidasan*
ent is God's gift to you. What you do with it is your gift back to God. ----------- - Original Message - From: Jim Gibson To: Perl Beginners Cc: Sent: Saturday, 23 February 2013 5:20 AM Subject: Re: Line Endings On F

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