> -----Original Message-----
> From: Bob Showalter [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, January 31, 2002 9:02 AM
> To: 'Dave Benware'; Beginners perl
> Subject: RE: What is the newline character (\n) equal to?
> 
> 
> > -----Original Message-----
> > From: Dave Benware [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, January 31, 2002 8:51 AM
> > To: Beginners perl
> > Subject: Re: What is the newline character (\n) equal to?
> > 
> > 
> > Dave Benware wrote:
> > > CR/LF has never been translated to a LF while reading a file
> > > for me.  If that were true, the whole situation would be
> > > transparent and I would have never asked the question it seems.
> > > I didn't see anything about this "translating" in the docs
> > > on the binmode function.
> > > 
> > > Bompa
> > 
> > Excuse me, I *do* see the "poop" you refered to in the binmode
> > function docs, however, it doesn't seem to be that way in reality.
> 
> A challenge, eh! OK, run the following program on a Windows machine:
> 
>    # create a string
>    $s = "foo\n";
>    print "length is ", length($s), "\n";
> 
>    # write it to a file
>    open F, ">foo.txt" or die $!;
>    print F $s;
>    close F;
> 
>    # see size of file
>    system "dir foo.txt";
> 
>    # read back from file
>    open F, "<foo.txt" or die $!;
>    $s = <F>;
>    close F;
>    print "length is ", length($s), "\n";
> 
>    # read from file in binary mode
>    open F, "<foo.txt" or die $!;
>    binmode F;
>    $s = <F>;
>    close F;
>    print "length is ", length($s), "\n";
> 
> When I run it on my Win98 PC, I get the following output:
> 
>    length is 4
> 
>     Volume in drive C has no label
>     Volume Serial Number is 07D1-031B
>     Directory of C:\Temp
> 
>    FOO      TXT             5  01-31-02  9:00a foo.txt
>             1 file(s)              5 bytes
>             0 dir(s)        7,104.59 MB free
>    length is 4
>    length is 5
> 
> So you can see that the string is 4 bytes long. When I write 
> it to the file,
> the file becomes 5 bytes, because the LF is converted to a 
> CR/LF pair. When
> I read it back in, the reverse conversion is made, so the 
> string becomes 4
> bytes again. When I call binmode, that conversion is not 
> made, so the 5
> bytes
> from the file are read in.
> 
> Make sense?

I forgot to add that my example was run with ActiveState Perl. If you are
running under the cygwin environment, you may not get the same results; I'm
not familiar with how that works. Under UNIX, all the sizes above would be
4 bytes.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to