Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Cygwin problem with 'print'

Reply
Thread Tools

Cygwin problem with 'print'

 
 
Fiaz Idris
Guest
Posts: n/a
 
      12-27-2003
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.
 
Reply With Quote
 
 
 
 
ko
Guest
Posts: n/a
 
      12-27-2003
Fiaz Idris wrote:
> 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
 
Reply With Quote
 
 
 
 
Ragnar Hafstaš
Guest
Posts: n/a
 
      12-27-2003

"Fiaz Idris" <> wrote in message
news: om...
> 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



 
Reply With Quote
 
Fiaz Idris
Guest
Posts: n/a
 
      12-27-2003
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
 
Reply With Quote
 
Fiaz Idris
Guest
Posts: n/a
 
      12-28-2003
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem Installing Win32::OLE under cygwin usenet Perl 2 05-22-2005 03:45 AM
confirm unsubscribe from cygwin@cygwin.com cygwin-help@cygwin.com Python 0 09-05-2003 04:42 PM
WELCOME to cygwin@cygwin.com cygwin-help@cygwin.com Python 1 09-05-2003 07:46 AM
confirm unsubscribe from cygwin-announce@cygwin.com cygwin-announce-help@cygwin.com Python 0 09-05-2003 01:29 AM
confirm unsubscribe from cygwin@cygwin.com cygwin-help@cygwin.com Python 0 09-04-2003 06:34 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57