Cygwin problem with 'print'

Discussion in 'Perl Misc' started by Fiaz Idris, Dec 27, 2003.

  1. Fiaz Idris

    Fiaz Idris Guest

    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.
     
    Fiaz Idris, Dec 27, 2003
    #1
    1. Advertising

  2. Fiaz Idris

    ko Guest

    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
     
    ko, Dec 27, 2003
    #2
    1. Advertising

  3. "Fiaz Idris" <> wrote in message
    news:...
    > 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
     
    Ragnar Hafstað, Dec 27, 2003
    #3
  4. Fiaz Idris

    Fiaz Idris Guest

    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
     
    Fiaz Idris, Dec 27, 2003
    #4
  5. Fiaz Idris

    Fiaz Idris Guest

    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.
     
    Fiaz Idris, Dec 28, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    465
  2. Replies:
    0
    Views:
    435
  3. WELCOME to

    , Sep 3, 2003, in forum: Python
    Replies:
    1
    Views:
    515
    Robin Becker
    Sep 5, 2003
  4. Replies:
    0
    Views:
    416
  5. keto
    Replies:
    0
    Views:
    968
Loading...

Share This Page