Cygwin problem with 'print'

F

Fiaz Idris

I am using Win98SE and cygwin
$ uname -a
CYGWIN_98-4.10 fiaz 1.5.5(0.94/3/2) 2003-09-20 16:31 i686 unknown unknown Cygwin

Say, I have a file 'stations.txt'

ABBEY WOOD
ABERGELE & PENSARN
CILMERI
CITY THAMESLINK
CLACTON
WATERINGBURY
WATERLOO (MERSEYSIDE)

and the following perlscript

while (<>) {
chomp;
$curr = $_;

$scurr = join '', (sort split //, $curr);
$scurr =~ s/\W//g;

# Behaviour inconsistent between ActivePerl5.8 & Cygwin Perl
# $curr although printed can't be seen.

print "$curr and $scurr\n";
}

The expected CORRECT result according to ActivePerl 5.8.0 is

ABBEY WOOD and ABBDEOOWY
ABERGELE &amp; PENSARN and AABEEEEGLNNPRRSamp
CILMERI and CEIILMR
CITY THAMESLINK and ACEHIIKLMNSTTY
CLACTON and ACCLNOT
WATERINGBURY and ABEGINRRTUWY
WATERLOO (MERSEYSIDE) and ADEEEEILMOORRSSTWY

But, the cygwin perl version
(This is perl, v5.8.2 built for cygwin-thread-multi-64int)

gives the following WRONG result.

and ABBDEOOWY
and AABEEEEGLNNPRRSamp
and CEIILMR
and ACEHIIKLMNSTTY
and ACCLNOT
and ABEGINRRTUWY
and ADEEEEILMOORRSSTWY

that is the first variable $curr is not shown. Although it is printed
somehow it gets backtracked and deletes and prints only from the space
and after.

Am I missing something? Is it a bug with Cygwin perl? Can someone please advise.
 
K

ko

Fiaz said:
I am using Win98SE and cygwin
$ uname -a
CYGWIN_98-4.10 fiaz 1.5.5(0.94/3/2) 2003-09-20 16:31 i686 unknown unknown Cygwin

Say, I have a file 'stations.txt'

[snip code]
The expected CORRECT result according to ActivePerl 5.8.0 is

[snip AS output]
But, the cygwin perl version
(This is perl, v5.8.2 built for cygwin-thread-multi-64int)

gives the following WRONG result.

[snip Cygwin output]
that is the first variable $curr is not shown. Although it is printed
somehow it gets backtracked and deletes and prints only from the space
and after.

Am I missing something? Is it a bug with Cygwin perl? Can someone
please advise.

This isn't a Perl problem, its a result Cygwin reading the text file in
DOS/Windows format. Copy and paste the original text file into another
text file from the Cygin shell using vi or whatever text editor you use
and try reruning the script.

You should also start all of your scripts like so:

use strict;
use warnings;

HTH - keith
 
R

Ragnar Hafstað

Fiaz Idris said:
I am using Win98SE and cygwin
while (<>) {
chomp;
cygwin uses NL as end of file marker, and chomp will remove that
however, you input file is probably a windows text file, where
lines are terminated with CR+NL, so you now have your line
with an extra CR at the end. try:
s/\r//g;
$curr = $_;

$scurr = join '', (sort split //, $curr);
$scurr =~ s/\W//g;

# Behaviour inconsistent between ActivePerl5.8 & Cygwin Perl
# $curr although printed can't be seen.

print "$curr and $scurr\n";

the CR in print on terminal has the effect to move the cursor to beginning
of line,
so the " $scurr" overwrites the $curr


gnari
 
F

Fiaz Idris

I happen to solve the problem myself and here is how.

But only if someone has any input on the following, please advise.

When 'vi stations.txt' i see the following line at the bottom.

"stations.txt" [dos]

That is the file is in [dos] format.

When I ':set', the 'fileformat=dos' can be seen.

So, what I did is ':set fileformat=unix' and the perl script works
as expected giving out both the $curr and $scurr.

When I ':l' on a line for example, I see no difference between
both 'dos' and 'unix' formats. So, what actually does the 'fileformat'
command do.

Thanks
 
F

Fiaz Idris

Thanx to both of you.

Now the script works as expected.

Basically, the problem is with the file format.

Changing DOS format to Unix format and everything works.

Infact, there were other problems due to this and now all of
them resolved.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top