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], ''));
>
>
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
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
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
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
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.
#!/
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/;
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;
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/
"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
} 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
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
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
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
> 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
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
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
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
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
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
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
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
"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
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
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
> 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
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.
<<<>>> <<<>>> <<<>>>
27 matches
Mail list logo