[30236] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1479 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 25 16:51:37 2008

Date: Fri, 25 Apr 2008 13:51:28 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 25 Apr 2008     Volume: 11 Number: 1479

Today's topics:
        Recursive directory read with File::Find kimanhtle@gmail.com
    Re: Recursive directory read with File::Find <someone@example.com>
    Re: Recursive directory read with File::Find kimanhtle@gmail.com
    Re: Recursive directory read with File::Find <someone@example.com>
    Re: Recursive directory read with File::Find <1usa@llenroc.ude.invalid>
    Re: Recursive directory read with File::Find kimanhtle@gmail.com
    Re: Recursive directory read with File::Find <someone@example.com>
    Re: Recursive directory read with File::Find kimanhtle@gmail.com
    Re: Recursive directory read with File::Find <benkasminbullock@gmail.com>
    Re: Recursive directory read with File::Find <tzz@lifelogs.com>
    Re: Recursive directory read with File::Find kimanhtle@gmail.com
    Re: Recursive directory read with File::Find <hjp-usenet2@hjp.at>
    Re: Recursive directory read with File::Find <1usa@llenroc.ude.invalid>
        Removing trailing newlines -  <John.Smith@invalid.com>
    Re: Removing trailing newlines -  <John.Smith@invalid.com>
    Re: Removing trailing newlines - <devnull4711@web.de>
    Re: Removing trailing newlines - <benkasminbullock@gmail.com>
    Re: Removing trailing newlines - <benkasminbullock@gmail.com>
    Re: Removing trailing newlines - <John.Smith@invalid.com>
    Re: Removing trailing newlines - <benkasminbullock@gmail.com>
    Re: Removing trailing newlines - <John.Smith@invalid.com>
    Re: Removing trailing newlines - <glex_no-spam@qwest-spam-no.invalid>
    Re: Removing trailing newlines - <syscjm@sumire.gwu.edu>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 22 Apr 2008 15:43:54 -0700 (PDT)
From: kimanhtle@gmail.com
Subject: Recursive directory read with File::Find
Message-Id: <6be0e3f7-a0b7-4cf5-9dc6-4d4b27bd19df@t54g2000hsg.googlegroups.com>

I would like to do a recursive read of a directory on my local
computer. Is this possible with File::Find? If not, is there any other
way to do it in Perl?


------------------------------

Date: Tue, 22 Apr 2008 22:54:03 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Recursive directory read with File::Find
Message-Id: <f0uPj.1514$XI1.775@edtnps91>

kimanhtle@gmail.com wrote:
> I would like to do a recursive read of a directory on my local
> computer. Is this possible with File::Find?

Yes.

> If not, is there any other way to do it in Perl?

TMTOWTDI

http://search.cpan.org/search?query=File%3A%3AFind&mode=all


John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


------------------------------

Date: Tue, 22 Apr 2008 20:14:23 -0700 (PDT)
From: kimanhtle@gmail.com
Subject: Re: Recursive directory read with File::Find
Message-Id: <9c1c4e83-24cb-4a0a-a888-9f191ff99111@w7g2000hsa.googlegroups.com>

On Apr 22, 6:54 pm, "John W. Krahn" <some...@example.com> wrote:
> kimanh...@gmail.com wrote:
> > I would like to do a recursive read of a directory on my local
> > computer. Is this possible with File::Find?
>
> Yes.
>
> > If not, is there any other way to do it in Perl?
>
> TMTOWTDI
>
> http://search.cpan.org/search?query=File%3A%3AFind&mode=all
>
> John
> --
> Perl isn't a toolbox, but a small machine shop where you
> can special-order certain sorts of tools at low cost and
> in short order.                            -- Larry Wall


Thanks! Would you happen to have an example? I only got it to work for
a UNIX path not a path on my local computer. It could be I didn't
escape the path right. For example, if I have "C:\projects\docs
\HUNGER_AWARENESS_04212008", would I have to pass it as "C:\\projects\
\docs\\HUNGER_AWARENESS_04212008"?



------------------------------

Date: Wed, 23 Apr 2008 03:21:52 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Recursive directory read with File::Find
Message-Id: <kXxPj.1464$PM5.318@edtnps92>

kimanhtle@gmail.com wrote:
> 
> On Apr 22, 6:54 pm, "John W. Krahn" <some...@example.com> wrote:
>> 
>> kimanh...@gmail.com wrote:
>>> 
>>> I would like to do a recursive read of a directory on my local
>>> computer. Is this possible with File::Find?
>> 
>> Yes.
>>
>>> If not, is there any other way to do it in Perl?
>> 
>> TMTOWTDI
>>
>> http://search.cpan.org/search?query=File%3A%3AFind&mode=all
> 
> Thanks! Would you happen to have an example? I only got it to work for
> a UNIX path not a path on my local computer. It could be I didn't
> escape the path right. For example, if I have "C:\projects\docs
> \HUNGER_AWARENESS_04212008", would I have to pass it as "C:\\projects\
> \docs\\HUNGER_AWARENESS_04212008"?

Or 'C:/projects/docs/HUNGER_AWARENESS_04212008' should work as well.


John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


------------------------------

Date: Wed, 23 Apr 2008 03:22:53 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Recursive directory read with File::Find
Message-Id: <Xns9A88EDD8411BCasu1cornelledu@127.0.0.1>

kimanhtle@gmail.com wrote in news:9c1c4e83-24cb-4a0a-a888-9f191ff99111
@w7g2000hsa.googlegroups.com:

> On Apr 22, 6:54 pm, "John W. Krahn" <some...@example.com> wrote:
>> kimanh...@gmail.com wrote:
>> > I would like to do a recursive read of a directory on my local
>> > computer. Is this possible with File::Find?
>>
>> Yes.
>>
>> > If not, is there any other way to do it in Perl?
>>
>> TMTOWTDI
>>
>> http://search.cpan.org/search?query=File%3A%3AFind&mode=all
>>
>> John
>> --

[ don't quote sigs ]

> 
> Thanks! Would you happen to have an example? I only got it to work for
> a UNIX path not a path on my local computer. It could be I didn't
> escape the path right. For example, if I have "C:\projects\docs
> \HUNGER_AWARENESS_04212008", would I have to pass it as "C:\\projects\
> \docs\\HUNGER_AWARENESS_04212008"?

From perlfaq5:

Why can't I use "C:\temp\foo" in DOS paths?  Why doesn't `C:\temp
\foo.exe` work?

We are not going to write your code for you when the documentation 
contains both working examples and answers to frequently answered 
questions.

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/


------------------------------

Date: Tue, 22 Apr 2008 21:36:32 -0700 (PDT)
From: kimanhtle@gmail.com
Subject: Re: Recursive directory read with File::Find
Message-Id: <be3dc321-5116-411a-a86c-83c172610aa7@s50g2000hsb.googlegroups.com>

On Apr 22, 11:22 pm, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
> kimanh...@gmail.com wrote in news:9c1c4e83-24cb-4a0a-a888-9f191ff99111
> @w7g2000hsa.googlegroups.com:
>
> > On Apr 22, 6:54 pm, "John W. Krahn" <some...@example.com> wrote:
> >> kimanh...@gmail.com wrote:
> >> > I would like to do a recursive read of a directory on my local
> >> > computer. Is this possible with File::Find?
>
> >> Yes.
>
> >> > If not, is there any other way to do it in Perl?
>
> >> TMTOWTDI
>
> >>http://search.cpan.org/search?query=File%3A%3AFind&mode=all
>
> >> John
> >> --
>
> [ don't quote sigs ]
>
>
>
> > Thanks! Would you happen to have an example? I only got it to work for
> > a UNIX path not a path on my local computer. It could be I didn't
> > escape the path right. For example, if I have "C:\projects\docs
> > \HUNGER_AWARENESS_04212008", would I have to pass it as "C:\\projects\
> > \docs\\HUNGER_AWARENESS_04212008"?
>
> From perlfaq5:
>
> Why can't I use "C:\temp\foo" in DOS paths?  Why doesn't `C:\temp
> \foo.exe` work?
>
> We are not going to write your code for you when the documentation
> contains both working examples and answers to frequently answered
> questions.
>
> Sinan
>
> --
> A. Sinan Unur <1...@llenroc.ude.invalid>
> (remove .invalid and reverse each component for email address)
>
> comp.lang.perl.misc guidelines on the WWW:http://www.rehabitation.com/clpmisc/

$upload_dir = 'C:\projects\docs\HUNGER_AWARENESS_04212008';
$upload_dir =~ s/\\/\//g;
find(\&handleFind, $upload_dir);

sub handleFind {
	my $foundFile = $File::Find::name;
	print "$foundFile and $_<br/>\n";
}

That was what I tried and it did not print the results of the
directory. But thank you all for taking the time to reply and bearing
with a newbie. I believe it is b/c my Perl script is on a UNIX server
that is trying to read directories on a local PC.


------------------------------

Date: Wed, 23 Apr 2008 06:11:10 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Recursive directory read with File::Find
Message-Id: <2qAPj.1625$XI1.212@edtnps91>

kimanhtle@gmail.com wrote:
> On Apr 22, 11:22 pm, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
>>
>> From perlfaq5:
>>
>> Why can't I use "C:\temp\foo" in DOS paths?  Why doesn't `C:\temp
>> \foo.exe` work?
> 
> $upload_dir = 'C:\projects\docs\HUNGER_AWARENESS_04212008';
> $upload_dir =~ s/\\/\//g;
> find(\&handleFind, $upload_dir);
> 
> sub handleFind {
> 	my $foundFile = $File::Find::name;
> 	print "$foundFile and $_<br/>\n";
> }
> 
> That was what I tried and it did not print the results of the
> directory. But thank you all for taking the time to reply and bearing
> with a newbie. I believe it is b/c my Perl script is on a UNIX server
> that is trying to read directories on a local PC.

UNIX does not have drive letters like 'C:' so it makes no sense to use 
that as part of the path on a UNIX system.

So the question then becomes how are you accessing the directories "on a 
local PC"?  Via SMB?  NFS?  FTP?  SSH?  ???


John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


------------------------------

Date: Wed, 23 Apr 2008 05:19:39 -0700 (PDT)
From: kimanhtle@gmail.com
Subject: Re: Recursive directory read with File::Find
Message-Id: <0143bfef-970d-4dbe-8360-138c75de7034@34g2000hsh.googlegroups.com>

On Apr 23, 2:11 am, "John W. Krahn" <some...@example.com> wrote:
> kimanh...@gmail.com wrote:
> > On Apr 22, 11:22 pm, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
>
> >> From perlfaq5:
>
> >> Why can't I use "C:\temp\foo" in DOS paths?  Why doesn't `C:\temp
> >> \foo.exe` work?
>
> > $upload_dir = 'C:\projects\docs\HUNGER_AWARENESS_04212008';
> > $upload_dir =~ s/\\/\//g;
> > find(\&handleFind, $upload_dir);
>
> > sub handleFind {
> >    my $foundFile = $File::Find::name;
> >    print "$foundFile and $_<br/>\n";
> > }
>
> > That was what I tried and it did not print the results of the
> > directory. But thank you all for taking the time to reply and bearing
> > with a newbie. I believe it is b/c my Perl script is on a UNIX server
> > that is trying to read directories on a local PC.
>
> UNIX does not have drive letters like 'C:' so it makes no sense to use
> that as part of the path on a UNIX system.
>
> So the question then becomes how are you accessing the directories "on a
> local PC"?  Via SMB?  NFS?  FTP?  SSH?  ???
>
> John
> --
> Perl isn't a toolbox, but a small machine shop where you
> can special-order certain sorts of tools at low cost and
> in short order.                            -- Larry Wall

I am at a dead end. I was trying to use the file upload field to have
user select a file then use javascript to get the directory name of
that file. This directory name was passed to a CGI script which I
thought I could use to traverse the directory listing recursively.
Then the CGI script would upload all the files in this directory.
However, now I am stuck at finding a way to recursively read a
directory on my local PC.


------------------------------

Date: Wed, 23 Apr 2008 12:31:38 +0000 (UTC)
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: Re: Recursive directory read with File::Find
Message-Id: <funa7a$ii0$3@ml.accsnet.ne.jp>

On Wed, 23 Apr 2008 05:19:39 -0700, kimanhtle wrote:

> I am at a dead end. I was trying to use the file upload field to have
> user select a file then use javascript to get the directory name of that
> file. This directory name was passed to a CGI script which I thought I
> could use to traverse the directory listing recursively. Then the CGI
> script would upload all the files in this directory. However, now I am
> stuck at finding a way to recursively read a directory on my local PC.

There isn't any way for the Unix server to read the directory on your 
local PC solely via a web browser, at least unless you totally disable 
all security in the browser or something. Imagine if it was possible to 
do things like that, we'd all be in serious trouble! You can send the 
string containing the directory to the Unix server, but unless the Unix 
server has some file system type of connection to your local PC (that is 
the "SMB?  NFS?  FTP?  SSH?" stuff which JK mentioned), it's not possible 
to look at the PC's file system with either a CGI script or JavaScript. 
That is just the nature of web servers and browsers.


------------------------------

Date: Wed, 23 Apr 2008 08:27:04 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Recursive directory read with File::Find
Message-Id: <86hcds66s7.fsf@lifelogs.com>

On Wed, 23 Apr 2008 05:19:39 -0700 (PDT) kimanhtle@gmail.com wrote: 

k> I am at a dead end. I was trying to use the file upload field to have
k> user select a file then use javascript to get the directory name of
k> that file. This directory name was passed to a CGI script which I
k> thought I could use to traverse the directory listing recursively.
k> Then the CGI script would upload all the files in this directory.
k> However, now I am stuck at finding a way to recursively read a
k> directory on my local PC.

Unfortunately the currently available standards only let you upload one
file at a time.  On the client, make a ZIP (or other format) archive of
the whole directory tree of interest and upload that.  On the server,
open and examine the archive with Archive::Zip or whatever module is
appropriate for the archive format you've chosen.

Ted


------------------------------

Date: Wed, 23 Apr 2008 07:23:13 -0700 (PDT)
From: kimanhtle@gmail.com
Subject: Re: Recursive directory read with File::Find
Message-Id: <3e637dee-f279-4885-886a-b6ccae771f10@m36g2000hse.googlegroups.com>

On Apr 23, 9:27=A0am, Ted Zlatanov <t...@lifelogs.com> wrote:
> On Wed, 23 Apr 2008 05:19:39 -0700 (PDT) kimanh...@gmail.com wrote:
>
> k> I am at a dead end. I was trying to use the file upload field to have
> k> user select a file then use javascript to get the directory name of
> k> that file. This directory name was passed to a CGI script which I
> k> thought I could use to traverse the directory listing recursively.
> k> Then the CGI script would upload all the files in this directory.
> k> However, now I am stuck at finding a way to recursively read a
> k> directory on my local PC.
>
> Unfortunately the currently available standards only let you upload one
> file at a time. =A0On the client, make a ZIP (or other format) archive of
> the whole directory tree of interest and upload that. =A0On the server,
> open and examine the archive with Archive::Zip or whatever module is
> appropriate for the archive format you've chosen.
>
> Ted

Thank you all so much for your help.
Ben, you are right, I did think of the security issue. But my boss
kept telling me there was a way to do recursive find. I searched the
web and found I could use an applet and then a perl script in the
backend. However, boss did not approve using applet.
Ted, the zip method was my last resort which I have working.


------------------------------

Date: Wed, 23 Apr 2008 19:01:37 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Recursive directory read with File::Find
Message-Id: <slrng0uqri.5jo.hjp-usenet2@hrunkner.hjp.at>

On 2008-04-23 12:31, Ben Bullock <benkasminbullock@gmail.com> wrote:
> On Wed, 23 Apr 2008 05:19:39 -0700, kimanhtle wrote:
>> I am at a dead end. I was trying to use the file upload field to have
>> user select a file then use javascript to get the directory name of that
>> file. This directory name was passed to a CGI script which I thought I
>> could use to traverse the directory listing recursively. Then the CGI
>> script would upload all the files in this directory. However, now I am
>> stuck at finding a way to recursively read a directory on my local PC.
>
> There isn't any way for the Unix server to read the directory on your 
> local PC solely via a web browser, at least unless you totally disable 
> all security in the browser or something. Imagine if it was possible to 
> do things like that, we'd all be in serious trouble! You can send the 
> string containing the directory to the Unix server, but unless the Unix 
> server has some file system type of connection to your local PC (that is 
> the "SMB?  NFS?  FTP?  SSH?" stuff which JK mentioned), it's not possible 
> to look at the PC's file system with either a CGI script or JavaScript. 

I think it is possible to give signed JavaScript the permission to do
this (similar to signed applets). But I've never looked at the details
and it's off-topic in this group anyway.

	hp


------------------------------

Date: Wed, 23 Apr 2008 23:45:06 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Recursive directory read with File::Find
Message-Id: <Xns9A89C8EB7785Casu1cornelledu@127.0.0.1>

"Peter J. Holzer" <hjp-usenet2@hjp.at> wrote in
news:slrng0uqri.5jo.hjp-usenet2@hrunkner.hjp.at: 

> On 2008-04-23 12:31, Ben Bullock <benkasminbullock@gmail.com> wrote:
 ...

>> unless the Unix server has some file system type of connection to
>> your local PC (that is the "SMB?  NFS?  FTP?  SSH?" stuff which JK
>> mentioned), it's not possible to look at the PC's file system with
>> either a CGI script or JavaScript. 
> 
> I think it is possible to give signed JavaScript the permission to do
> this (similar to signed applets). But I've never looked at the details
> and it's off-topic in this group anyway.

AFAIK, works only on Firefox. So, if that is a suitable restriction for 
the OP, the next place to check is Firefox documentation on how to do 
it.

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/


------------------------------

Date: Wed, 23 Apr 2008 14:31:18 +0300
From: John <John.Smith@invalid.com>
Subject: Removing trailing newlines - 
Message-Id: <qf6u045umfcg83tl9907sqq4k0cise7s9o@4ax.com>

I want to read a file line-by line and write it line by line to another file.
Regarless of environment I want newline start with DOS's \x0d\x0a

Here's the code snippet:

$ii=open(MYHAN,"<file01.htm");
open(MYHAN2,">>receive.htm");
binmode(MYHAN);
binmode(MYHAN2);
while ($line=<MYHAN>)
   {
   chomp($line);     
   $line=~s/\x0d//g;  # probably unnecessary
   $line=~s/\x0a//g;
   print MYHAN2 $rivi."testing\x0d\x0a";
   }
close MYHAN;
closeMYHAN2;


The problem is that I get in "receive.txt" I get ending
"balhblahtesting[CR][CR][LF]" where [CR] mean carriage return and [LF] line feed.

Why is this happening? I've chomped and ~s'd the $line. I've also binmoded both
file handles for good measure. 


------------------------------

Date: Wed, 23 Apr 2008 14:56:10 +0300
From: John <John.Smith@invalid.com>
Subject: Re: Removing trailing newlines - 
Message-Id: <qr8u04pvkqdokjrqi6c09md3b3nq7ojind@4ax.com>

John <John.Smith@invalid.com> wrote:

>I want to read a file line-by line and write it line by line to another file.
>Regarless of environment I want newline start with DOS's \x0d\x0a
>
>Here's the code snippet:
>
$ii=open(MYHAN,"<file01.htm");
open(MYHAN2,">>receive.htm");
binmode(MYHAN);
binmode(MYHAN2);
while ($line=<MYHAN>)
   {
   chomp($line);     
   $line=~s/\x0d//g;  # probably unnecessary
   $line=~s/\x0a//g;
   print MYHAN2 $line."testing\x0d\x0a";
   }
close MYHAN;
close MYHAN2;

oops there was a typo - I had cut the code from another source but problem
remains teh same.

>
>
>The problem is that I get in "receive.txt" I get ending
>"balhblahtesting[CR][CR][LF]" where [CR] mean carriage return and [LF] line feed.
>
>Why is this happening? I've chomped and ~s'd the $line. I've also binmoded both
>file handles for good measure. 


------------------------------

Date: Wed, 23 Apr 2008 14:00:44 +0200
From: Frank Seitz <devnull4711@web.de>
Subject: Re: Removing trailing newlines -
Message-Id: <678mnnF2nci9gU1@mid.individual.net>

John wrote:
> 
> The problem is that I get in "receive.txt" I get ending
> "balhblahtesting[CR][CR][LF]" where [CR] mean carriage return and [LF] line feed.
> 
> Why is this happening? I've chomped and ~s'd the $line.

chomp() removes the value of $/ - i.e. LF on Unix, not CRLF.

Frank
-- 
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel


------------------------------

Date: Wed, 23 Apr 2008 12:19:45 +0000 (UTC)
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: Re: Removing trailing newlines -
Message-Id: <fun9h1$ii0$1@ml.accsnet.ne.jp>

On Wed, 23 Apr 2008 14:31:18 +0300, John wrote:

> Why is this happening? I've chomped and ~s'd the $line. I've also
> binmoded both file handles for good measure.

I rewrote your code as follows and didn't get the error you mention on 
either Ubuntu Linux or Windows or Cygwin:

#!/usr/bin/perl
use warnings;
use strict;
open(MYHAN,"<", "testcrs.pl") or die $!;
open(MYHAN2,">", "receive.txt") or die $!;
binmode(MYHAN);
binmode(MYHAN2);
while (my $line=<MYHAN>)
   {
   chomp($line);     
   $line=~s/\x0d//g;  # probably unnecessary
   $line=~s/\x0a//g;
   print MYHAN2 $line." testing R\x0dS\x0aT";
   }
close MYHAN;
close MYHAN2;

Note that the "binmode" is essential here - without that what you 
describe is the expected behaviour on Windows. The most likely cause of 
the problem is that "open (MYHAN2" ... actually failed and you were 
looking at an old version of the file before you'd used the "binmode" 
statement, or perhaps you didn't scroll down far enough (since originally 
it was appending to receive.txt rather than overwriting it).



------------------------------

Date: Wed, 23 Apr 2008 12:20:50 +0000 (UTC)
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: Re: Removing trailing newlines -
Message-Id: <fun9j2$ii0$2@ml.accsnet.ne.jp>

On Wed, 23 Apr 2008 14:00:44 +0200, Frank Seitz wrote:

> John wrote:
>> 
>> The problem is that I get in "receive.txt" I get ending
>> "balhblahtesting[CR][CR][LF]" where [CR] mean carriage return and [LF]
>> line feed.
>> 
>> Why is this happening? I've chomped and ~s'd the $line.
> 
> chomp() removes the value of $/ - i.e. LF on Unix, not CRLF.

That can't be the solution, because he also used global substitutions to 
remove any line feeds or carriage returns in the string $line.


------------------------------

Date: Wed, 23 Apr 2008 15:35:47 +0300
From: John <John.Smith@invalid.com>
Subject: Re: Removing trailing newlines -
Message-Id: <83bu04562b2s4jaq2snp5rshsfun50354l@4ax.com>

Ben Bullock <benkasminbullock@gmail.com> wrote:

>On Wed, 23 Apr 2008 14:31:18 +0300, John wrote:
>
>> Why is this happening? I've chomped and ~s'd the $line. I've also
>> binmoded both file handles for good measure.
>
>I rewrote your code as follows and didn't get the error you mention on 
>either Ubuntu Linux or Windows or Cygwin:
>
>#!/usr/bin/perl
>use warnings;
>use strict;
>open(MYHAN,"<", "testcrs.pl") or die $!;
>open(MYHAN2,">", "receive.txt") or die $!;
>binmode(MYHAN);
>binmode(MYHAN2);
>while (my $line=<MYHAN>)
>   {
>   chomp($line);     
>   $line=~s/\x0d//g;  # probably unnecessary
>   $line=~s/\x0a//g;
>   print MYHAN2 $line." testing R\x0dS\x0aT";
>   }
>close MYHAN;
>close MYHAN2;
>
>Note that the "binmode" is essential here - without that what you 
>describe is the expected behaviour on Windows. The most likely cause of 
>the problem is that "open (MYHAN2" ... actually failed and you were 
>looking at an old version of the file before you'd used the "binmode" 
>statement, or perhaps you didn't scroll down far enough (since originally 
>it was appending to receive.txt rather than overwriting it).



I copied you example and still get the problem. The receive.txt looks like below
#!/usr/bin/perl testing R
S
Tuse warnings; testing R
S
Tuse strict; testing R
S
T testing R
S
Tprint "Content-Type: text/html; charset=iso-8859-1\n\n"; testing R
S
 ....

 I added some html lines:

#!/usr/bin/perl
use warnings;
use strict;

print "Content-Type: text/html; charset=iso-8859-1\n\n";
print '<html>';
print '<head>';
print '<title>Hello</title>';
print '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">';
print '</head>';


open(MYHAN,"<", "testcrs.pl") or die $!;
open(MYHAN2,">", "receive.txt") or die $!;
binmode(MYHAN);
binmode(MYHAN2);
while (my $line=<MYHAN>)
   {
   chomp($line);     
   $line=~s/\x0d//g;  # probably unnecessary
   $line=~s/\x0a//g;
   print MYHAN2 $line." testing R\x0dS\x0aT";
   }
close MYHAN;
close MYHAN2;

print '</html>';


------------------------------

Date: Wed, 23 Apr 2008 12:50:23 +0000 (UTC)
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: Re: Removing trailing newlines -
Message-Id: <funbaf$kod$1@ml.accsnet.ne.jp>

On Wed, 23 Apr 2008 15:35:47 +0300, John wrote:

> I copied you example and still get the problem.

It's probably an error elsewhere, not in Perl.


------------------------------

Date: Wed, 23 Apr 2008 17:44:22 +0300
From: John <John.Smith@invalid.com>
Subject: Re: Removing trailing newlines -
Message-Id: <bliu04t8nn60lr2mvh291q26n3t903vhgt@4ax.com>

Ben Bullock <benkasminbullock@gmail.com> wrote:

>On Wed, 23 Apr 2008 15:35:47 +0300, John wrote:
>
>> I copied you example and still get the problem.
>
>It's probably an error elsewhere, not in Perl.

You are right! My bad. Wasted hours on this. The problem was that when I
downloaded the file the ftp client program was set to "Auto" and it added the
extra CR's. When I set it to "Binary" the files came down OK.

Thanks for the help!


------------------------------

Date: Thu, 24 Apr 2008 11:44:54 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Removing trailing newlines -
Message-Id: <4810b906$0$48228$815e3792@news.qwest.net>

John wrote:

> I copied you example and still get the problem. The receive.txt looks like below
[...]
>  I added some html lines:

Yeah, that's usually the first step in debugging any program.

1. Always add HTML. That'll fix 99% of your coding errors.

:-)


------------------------------

Date: Thu, 24 Apr 2008 15:29:11 -0500
From: Chris Mattern <syscjm@sumire.gwu.edu>
Subject: Re: Removing trailing newlines -
Message-Id: <slrng11rcm.lp2.syscjm@sumire.gwu.edu>

On 2008-04-24, J. Gleixner <glex_no-spam@qwest-spam-no.invalid> wrote:
> John wrote:
>
>> I copied you example and still get the problem. The receive.txt looks like below
> [...]
>>  I added some html lines:
>
> Yeah, that's usually the first step in debugging any program.
>
> 1. Always add HTML. That'll fix 99% of your coding errors.
>
>:-)

That's ridiculous.  You have to add XML.  XML solves *everything*.


-- 
             Christopher Mattern

NOTICE
Thank you for noticing this new notice
Your noticing it has been noted
And will be reported to the authorities


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 1479
***************************************


home help back first fref pref prev next nref lref last post