[32687] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3845 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 3 14:55:54 2013

Date: Wed, 26 Dec 2012 02:17:17 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 26 Dec 2012     Volume: 11 Number: 3845

Today's topics:
        Sample program from Programming Perl (Camel book) not r hiabhijeet@gmail.com
    Re: Sample program from Programming Perl (Camel book) n <vilain@NOspamcop.net>
    Re: Sample program from Programming Perl (Camel book) n hiabhijeet@gmail.com
    Re: Sample program from Programming Perl (Camel book) n hiabhijeet@gmail.com
    Re: Sample program from Programming Perl (Camel book) n hiabhijeet@gmail.com
    Re: Sample program from Programming Perl (Camel book) n <rweikusat@mssgmbh.com>
    Re: Sample program from Programming Perl (Camel book) n <michael.vilain@gmail.com>
    Re: Sample program from Programming Perl (Camel book) n <rweikusat@mssgmbh.com>
    Re: Sample program from Programming Perl (Camel book) n <vilain@NOspamcop.net>
    Re: Sample program from Programming Perl (Camel book) n <rweikusat@mssgmbh.com>
    Re: split() and @_: Perl changed between 5.8 and 5.14 (Greg Bacon)
    Re: we are all aware of the physical risks associated w <ralph@happydays.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 23 Dec 2012 19:00:11 -0800 (PST)
From: hiabhijeet@gmail.com
Subject: Sample program from Programming Perl (Camel book) not running as expected
Message-Id: <4b54d89f-1d4c-4ec1-a995-a5bdf38202d3@googlegroups.com>

I am trying to execute the following sample program on WINDOWS but its not =
executing as expected. Its only reading the first line from the file and di=
splaying it. Its not reading the rest of the lines -=20

open(GRADES, "grades") or die "Can't open grades: $!\n";
while(defined($line =3D <GRADES>)) {
	print "[1] - $line\n";
	($student, $grade) =3D split(" ", $line);
	$grades{$student} .=3D $grade . " ";
	print "[2] - $student\t$grade\n";
}

foreach $student (sort keys %grades) {
	print "[3] - $student\n";
	$scores =3D 0;
	$total =3D 0;
 	@grades =3D split(" ", $grades{$student});
 	foreach $grade (@grades) {
 		$total +=3D $grade;
 		$scores++;
	}
	$average =3D $total / $scores;
	print "$student: $grades{$student}\tAverage: $average\n";
}

Please note - "grades" is a file that contains below data -=20

No=EBl 25
Ben 76
Clementine 49
Norm 66
Chris 92
Doug 42
Carol 25
Ben 12
Clementine 0
Norm 66


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

Date: Sun, 23 Dec 2012 20:08:33 -0800
From: Michael Vilain <vilain@NOspamcop.net>
Subject: Re: Sample program from Programming Perl (Camel book) not running as expected
Message-Id: <vilain-AD7302.20083123122012@news.individual.net>

In article <4b54d89f-1d4c-4ec1-a995-a5bdf38202d3@googlegroups.com>,
 hiabhijeet@gmail.com wrote:

> I am trying to execute the following sample program on WINDOWS but its not 
> executing as expected. Its only reading the first line from the file and 
> displaying it. Its not reading the rest of the lines - 
> 
> open(GRADES, "grades") or die "Can't open grades: $!\n";
> while(defined($line = <GRADES>)) {
> 	print "[1] - $line\n";
> 	($student, $grade) = split(" ", $line);
> 	$grades{$student} .= $grade . " ";
> 	print "[2] - $student\t$grade\n";
> }
> 
> foreach $student (sort keys %grades) {
> 	print "[3] - $student\n";
> 	$scores = 0;
> 	$total = 0;
>  	@grades = split(" ", $grades{$student});
>  	foreach $grade (@grades) {
>  		$total += $grade;
>  		$scores++;
> 	}
> 	$average = $total / $scores;
> 	print "$student: $grades{$student}\tAverage: $average\n";
> }
> 
> Please note - "grades" is a file that contains below data - 
> 
> Noël 25
> Ben 76
> Clementine 49
> Norm 66
> Chris 92
> Doug 42
> Carol 25
> Ben 12
> Clementine 0
> Norm 66

Check the line endings on the file.  I don't know if the Windows Perl 
implementation uses "\n" as a line ending as UNIX and MacOS versions of 
Perl or "\r\n" for Windows standard.  How do you know what is what?  
That depends on the editor you're using, I think.

-- 
DeeDee, don't press that button!  DeeDee!  NO!  Dee...
[I filter all Goggle Groups posts, so any reply may be automatically ignored]




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

Date: Sun, 23 Dec 2012 20:44:43 -0800 (PST)
From: hiabhijeet@gmail.com
Subject: Re: Sample program from Programming Perl (Camel book) not running as expected
Message-Id: <117810a0-92b0-48ca-a3fe-2c5829c01235@googlegroups.com>

On Monday, 24 December 2012 12:08:33 UTC+8, Michael Vilain wrote:
> In article <4b54d89f-1d4c-4ec1-a995-a5bdf38202d3@googlegroups.com>, hiabh=
ijeet@gmail.com wrote: > I am trying to execute the following sample progra=
m on WINDOWS but its not > executing as expected. Its only reading the firs=
t line from the file and > displaying it. Its not reading the rest of the l=
ines - > > open(GRADES, "grades") or die "Can't open grades: $!\n"; > while=
(defined($line =3D <GRADES>)) { > print "[1] - $line\n"; > ($student, $grad=
e) =3D split(" ", $line); > $grades{$student} .=3D $grade . " "; > print "[=
2] - $student\t$grade\n"; > } > > foreach $student (sort keys %grades) { > =
print "[3] - $student\n"; > $scores =3D 0; > $total =3D 0; > @grades =3D sp=
lit(" ", $grades{$student}); > foreach $grade (@grades) { > $total +=3D $gr=
ade; > $scores++; > } > $average =3D $total / $scores; > print "$student: $=
grades{$student}\tAverage: $average\n"; > } > > Please note - "grades" is a=
 file that contains below data - > > No=EBl 25 > Ben 76 > Clementine 49 > N=
orm 66 > Chris 92 > Doug 42 > Carol 25 > Ben 12 > Clementine 0 > Norm 66 Ch=
eck the line endings on the file. I don't know if the Windows Perl implemen=
tation uses "\n" as a line ending as UNIX and MacOS versions of Perl or "\r=
\n" for Windows standard. How do you know what is what? That depends on the=
 editor you're using, I think. -- DeeDee, don't press that button! DeeDee! =
NO! Dee... [I filter all Goggle Groups posts, so any reply may be automatic=
ally ignored]

Thanks. Thats what.. what would make this program work on windows. I used U=
ltraEdit to convert this file to DOS.


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

Date: Sun, 23 Dec 2012 20:46:12 -0800 (PST)
From: hiabhijeet@gmail.com
Subject: Re: Sample program from Programming Perl (Camel book) not running as expected
Message-Id: <1c828a87-c91b-4f82-8c70-6fb7786e096d@googlegroups.com>

Thanks. Yes... would like to know what would make this program work on Windows. About the file format - I used UltraEdit to save this file in DOS mode.


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

Date: Sun, 23 Dec 2012 20:53:04 -0800 (PST)
From: hiabhijeet@gmail.com
Subject: Re: Sample program from Programming Perl (Camel book) not running as expected
Message-Id: <728dc8ee-3862-4816-9ed8-cb647ed3ea5c@googlegroups.com>

Hey.. got this to work. Earlier I had copy pasted the file contents from the book pdf to notepad. Now reworte the data from scratch in a new file (using UltraEdit) and saved it as it is. Now program works fine!!


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

Date: Mon, 24 Dec 2012 19:50:50 +0000
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: Sample program from Programming Perl (Camel book) not running as expected
Message-Id: <87r4mfqlet.fsf@sapphire.mobileactivedefense.com>

Michael Vilain <vilain@NOspamcop.net> writes:
>  hiabhijeet@gmail.com wrote:
>
>> I am trying to execute the following sample program on WINDOWS but its not 
>> executing as expected. Its only reading the first line from the file and 
>> displaying it. Its not reading the rest of the lines - 
>> 

[...]

> Check the line endings on the file.  I don't know if the Windows Perl 
> implementation uses "\n" as a line ending as UNIX and MacOS versions of 
> Perl or "\r\n" for Windows standard.

This is supposed to be transparent for files opened in text mode (the
default): A WinDOS/2-perl should translate \xd\xa to 'a logical \n' on
input and translate this 'logical \n' back to \xd\xa on output except
if binmode was used to disable this behaviour.

NB: I haven't tested this.


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

Date: Mon, 24 Dec 2012 17:09:42 -0800 (PST)
From: MeV <michael.vilain@gmail.com>
Subject: Re: Sample program from Programming Perl (Camel book) not running as expected
Message-Id: <384a0832-d10f-4c85-9f00-7c61a938981e@googlegroups.com>

On Monday, December 24, 2012 11:50:50 AM UTC-8, Rainer Weikusat wrote:
> Michael Vilain <vilain@NOspamcop.net> writes:
>=20
> >  hiabhijeet@gmail.com wrote:
> >
> >> I am trying to execute the following sample program on WINDOWS but its=
 not=20
> >> executing as expected. Its only reading the first line from the file a=
nd=20
> >> displaying it. Its not reading the rest of the lines -=20
> >>=20
>=20
>=20
>=20
> [...]
>=20
> > Check the line endings on the file.  I don't know if the Windows Perl=
=20
> > implementation uses "\n" as a line ending as UNIX and MacOS versions of=
=20
> > Perl or "\r\n" for Windows standard.
>=20
> This is supposed to be transparent for files opened in text mode (the
> default): A WinDOS/2-perl should translate \xd\xa to 'a logical \n' on
> input and translate this 'logical \n' back to \xd\xa on output except
> if binmode was used to disable this behaviour.
>=20
>=20
>=20
> NB: I haven't tested this.

It definitely isn't transparent on MacOS X.  If you open a Windows-formatte=
d file in MacOS X perl, you get the exact behavior he described.  That's wh=
at twigged me to the problem.  If you change the file to UNIX line-endings,=
 the problem goes away and perl works as expected.

Don't know what editors there are on Windows that support setting or changi=
ng the line-endings.  vi on Unix will tell you if a Windows file has ^M lin=
e endings.  BBEdit and Textwrangler on MacOS supports this trivially.


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

Date: Tue, 25 Dec 2012 15:32:00 +0000
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: Sample program from Programming Perl (Camel book) not running as expected
Message-Id: <87pq1y87wv.fsf@sapphire.mobileactivedefense.com>

MeV <michael.vilain@gmail.com> writes:
> On Monday, December 24, 2012 11:50:50 AM UTC-8, Rainer Weikusat wrote:
>> Michael Vilain <vilain@NOspamcop.net> writes:
>> 
>> >  hiabhijeet@gmail.com wrote:
>> >
>> >> I am trying to execute the following sample program on WINDOWS but its not 
>> >> executing as expected. Its only reading the first line from the file and 
>> >> displaying it. Its not reading the rest of the lines - 
>> >> 
>> 
>> 
>> 
>> [...]
>> 
>> > Check the line endings on the file.  I don't know if the Windows Perl 
>> > implementation uses "\n" as a line ending as UNIX and MacOS versions of 
>> > Perl or "\r\n" for Windows standard.
>> 
>> This is supposed to be transparent for files opened in text mode (the
>> default): A WinDOS/2-perl should translate \xd\xa to 'a logical \n' on
>> input and translate this 'logical \n' back to \xd\xa on output except
>> if binmode was used to disable this behaviour.
>> 
>> 
>> 
>> NB: I haven't tested this.
>
> It definitely isn't transparent on MacOS X.  If you open a
> Windows-formatted file in MacOS X perl, you get the exact behavior
> he described. That's what twigged me to the problem.  If you change
> the file to UNIX line-endings, the problem goes away and perl works
> as expected.

Well, a MAC OS X perl is supposed to handle MAC OS X text files
'transparently' (suprising, ain't int?) in the same way a Windows perl
is supposed to handle Windows text files transparently ...


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

Date: Tue, 25 Dec 2012 09:14:23 -0800
From: Michael Vilain <vilain@NOspamcop.net>
Subject: Re: Sample program from Programming Perl (Camel book) not running as expected
Message-Id: <vilain-19DA1F.09142325122012@news.individual.net>

In article <87pq1y87wv.fsf@sapphire.mobileactivedefense.com>,
 Rainer Weikusat <rweikusat@mssgmbh.com> wrote:

> MeV <michael.vilain@gmail.com> writes:
> > On Monday, December 24, 2012 11:50:50 AM UTC-8, Rainer Weikusat wrote:
> >> Michael Vilain <vilain@NOspamcop.net> writes:
> >> 
> >> >  hiabhijeet@gmail.com wrote:
> >> >
> >> >> I am trying to execute the following sample program on WINDOWS but its 
> >> >> not 
> >> >> executing as expected. Its only reading the first line from the file 
> >> >> and 
> >> >> displaying it. Its not reading the rest of the lines - 
> >> >> 
> >> 
> >> 
> >> 
> >> [...]
> >> 
> >> > Check the line endings on the file.  I don't know if the Windows Perl 
> >> > implementation uses "\n" as a line ending as UNIX and MacOS versions of 
> >> > Perl or "\r\n" for Windows standard.
> >> 
> >> This is supposed to be transparent for files opened in text mode (the
> >> default): A WinDOS/2-perl should translate \xd\xa to 'a logical \n' on
> >> input and translate this 'logical \n' back to \xd\xa on output except
> >> if binmode was used to disable this behaviour.
> >> 
> >> 
> >> 
> >> NB: I haven't tested this.
> >
> > It definitely isn't transparent on MacOS X.  If you open a
> > Windows-formatted file in MacOS X perl, you get the exact behavior
> > he described. That's what twigged me to the problem.  If you change
> > the file to UNIX line-endings, the problem goes away and perl works
> > as expected.
> 
> Well, a MAC OS X perl is supposed to handle MAC OS X text files
> 'transparently' (suprising, ain't int?) in the same way a Windows perl
> is supposed to handle Windows text files transparently ...

There's a big difference between 'supposed to' and actuality.  Kinda 
like the architect's plans and the builder's 'built-as' drawings.

Googling for 'perl windows line endings' gives lots of solutions to this 
problem.  But if the OP didn't know there was a problem to begin with, 
then they'd be mystified by why Windows Perl doesn't work the same as 
documented in the Camel book.

I had to write a perl script to convert and import a CSV file into MySQL 
but I never new where that script would be coming from.  So I had to 
build the line-ending detection into my code.  I think it was quite easy 
once you know that's an issue.

-- 
DeeDee, don't press that button!  DeeDee!  NO!  Dee...
[I filter all Goggle Groups posts, so any reply may be automatically ignored]




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

Date: Tue, 25 Dec 2012 17:28:28 +0000
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: Sample program from Programming Perl (Camel book) not running as expected
Message-Id: <87y5gmujlv.fsf@sapphire.mobileactivedefense.com>

Michael Vilain <vilain@NOspamcop.net> writes:
> In article <87pq1y87wv.fsf@sapphire.mobileactivedefense.com>,
>  Rainer Weikusat <rweikusat@mssgmbh.com> wrote:
>> MeV <michael.vilain@gmail.com> writes:

[...]

>> >> >> I am trying to execute the following sample program on WINDOWS but its 
>> >> >> not 
>> >> >> executing as expected. Its only reading the first line from the file 
>> >> >> and 
>> >> >> displaying it. Its not reading the rest of the lines - 
>> >> >> 
>> >> 
>> >> 
>> >> 
>> >> [...]
>> >> 
>> >> > Check the line endings on the file.  I don't know if the Windows Perl 
>> >> > implementation uses "\n" as a line ending as UNIX and MacOS versions of 
>> >> > Perl or "\r\n" for Windows standard.
>> >> 
>> >> This is supposed to be transparent for files opened in text mode (the
>> >> default): A WinDOS/2-perl should translate \xd\xa to 'a logical \n' on
>> >> input and translate this 'logical \n' back to \xd\xa on output except
>> >> if binmode was used to disable this behaviour.
>> >> 
>> >> 
>> >> 
>> >> NB: I haven't tested this.
>> >
>> > It definitely isn't transparent on MacOS X.  If you open a
>> > Windows-formatted file in MacOS X perl, you get the exact behavior
>> > he described. That's what twigged me to the problem.  If you change
>> > the file to UNIX line-endings, the problem goes away and perl works
>> > as expected.
>> 
>> Well, a MAC OS X perl is supposed to handle MAC OS X text files
>> 'transparently' (suprising, ain't int?) in the same way a Windows perl
>> is supposed to handle Windows text files transparently ...
>
> There's a big difference between 'supposed to' and actuality.  Kinda 
> like the architect's plans and the builder's 'built-as' drawings.

In this case, this has been documented functionality since
I-don't-know-when (presumably, since a Perl port of Windows existed)
and consequently, the chances that a _Windows_ perl can't handle
_Windows_ text files despite the documentation says it can are IMO
very slim. OTOH, a _UNIX(*)_ perl won't be able to handle 'Windows text
files' in 'text mode' because it expects _UNIX(*)_ text files ...

> Googling for 'perl windows line endings' gives lots of solutions to this 
> problem.

 ... which happens to be consistent with your observation of a certain
(Free)BSD bastard and all of these "someone wrote this with notepad
and while it works on my laptop, it doesn't work on the webserver !!1"
tips.


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

Date: Mon, 24 Dec 2012 00:24:43 -0600
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: split() and @_: Perl changed between 5.8 and 5.14
Message-Id: <m6SdnUGweMO2aErNnZ2dnUVZ_o2dnZ2d@posted.hiwaay2>

In article <871uev1bkl.fsf@sapphire.mobileactivedefense.com>,
    Rainer Weikusat  <rweikusat@mssgmbh.com> wrote:

: A old joke-example of a German sentence goes like this: Derjenige, der
: den Taeter, der den Pfahl, der an der Bruecke, die auf dem Weg nach
: Worms liegt, steht, umgeworfen hat, anzeigt, erhaelt eine Belohnung.

That reminds me of a Dominus quip: "Well, I realize that I'm getting
into the reason why your argument that my argument that Cardwell's
argument doesn't apply doesn't apply doesn't apply. But I think your
argument doesn't apply."

Amusing in both cases!

: [...]

Greg


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

Date: Sun, 23 Dec 2012 20:22:00 -0500
From: Ralph Malph <ralph@happydays.com>
Subject: Re: we are all aware of the physical risks associated with multiple sex partners, but could these choices also put you at risk for heartache?
Message-Id: <cd448$50d7b27e$484a174a$24797@news.eurofeeds.com>

Constantine wrote:
> we are all aware of the physical risks associated with multiple sex partners
[snip]

Not in a programming newsgroup my friend!


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

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:

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

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 3845
***************************************


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