unwanted leading whitespace when using print

Discussion in 'Perl Misc' started by rroo, Mar 26, 2008.

  1. rroo

    rroo Guest

    The following bit of code adds unwanted whitespace at the beginning of
    some lines. It looks like the /n in the added text is not interpret
    correctly. Using komodo debugger I cannot pinpoint the problem. The
    generic array is filled correctly, only after the print the output is
    incorrect.
    See code and output:
    <begin code>
    my @generic;
    my @allGeneric;

    # read some lines from file, no specific mark up
    # store matching lines in @genreric
    FH = open "<", "Some file.txt";

    while (<FH>)
    {
    if ($line =~ /some match/)
    {
    push (@generic, $line);
    }
    }
    close FH;

    #add some trailing text
    #remove first element since it si always empty due to push

    push (@generic, "\nSee some place: \n");
    splice (@generic, 0,1);
    push (@allGeneric,"*"x80 . "\n");
    push (@allGeneric,@generic);

    print "The system folder is ...\n\n";
    print "===== Generic actions =====\n";
    print "@allGeneric\n";
    <end code>

    This produces:
    <begin output>
    The system folder is ...


    ===== Generic actions =====
    ********************************************************************************
    Ja, we hebben hier een heleboel werk om alles goed te krijgen met
    allerlei linefeeds en line dingetjes waar ik niet zo'n goed zicht op
    heb in perl gebruik. Daarom is het af en toe ook wel lastig, maar toch
    ook wel (heel) erg vaak.

    En soms: treedt er een 'panic' of "dubbele quote" op, maar mag dat?


    See some place:

    <end output>

    Note the leading whitespace before 'Ja, ' and before 'En soms'.

    Any help?
    ( I am using
    This is perl, v5.8.7 built for MSWin32-x86-multi-thread
    (with 7 registered patches, see perl -V for more detail)

    Copyright 1987-2005, Larry Wall

    Binary build 813 [148120] provided by ActiveState http://www.ActiveState.com
    ActiveState is a division of Sophos.
    Built Jun 6 2005 13:36:37
    )
     
    rroo, Mar 26, 2008
    #1
    1. Advertising

  2. rroo

    rroo Guest

    On Mar 26, 10:59 am, rroo <> wrote:
    > The following bit of code adds unwanted whitespace at the beginning of
    > some lines. It looks like the /n in the added text is not interpret
    > correctly. Using komodo debugger I cannot pinpoint the problem. The
    > generic array is filled correctly, only after the print the output is
    > incorrect.
    > See code and output:
    > <begin code>
    > my @generic;
    > my @allGeneric;
    >
    > # read some lines from file, no specific mark up
    > # store matching lines in @genreric
    > FH = open "<", "Some file.txt";
    >
    > while (<FH>)
    > {
    > if ($line =~ /some match/)
    > {
    > push (@generic, $line);
    > }}
    >
    > close FH;
    >
    > #add some trailing text
    > #remove first element since it si always empty due to push
    >
    > push (@generic, "\nSee some place: \n");
    > splice (@generic, 0,1);
    > push (@allGeneric,"*"x80 . "\n");
    > push (@allGeneric,@generic);
    >
    > print "The system folder is ...\n\n";
    > print "===== Generic actions =====\n";
    > print "@allGeneric\n";
    > <end code>
    >
    > This produces:
    > <begin output>
    > The system folder is ...
    >
    > ===== Generic actions =====
    > ********************************************************************************
    > Ja, we hebben hier een heleboel werk om alles goed te krijgen met
    > allerlei linefeeds en line dingetjes waar ik niet zo'n goed zicht op
    > heb in perl gebruik. Daarom is het af en toe ook wel lastig, maar toch
    > ook wel (heel) erg vaak.
    >
    > En soms: treedt er een 'panic' of "dubbele quote" op, maar mag dat?
    >
    > See some place:
    >
    > <end output>
    >
    > Note the leading whitespace before 'Ja, ' and before 'En soms'.
    >
    > Any help?
    > ( I am using
    > This is perl, v5.8.7 built for MSWin32-x86-multi-thread
    > (with 7 registered patches, see perl -V for more detail)
    >
    > Copyright 1987-2005, Larry Wall
    >
    > Binary build 813 [148120] provided by ActiveStatehttp://www.ActiveState.com
    > ActiveState is a division of Sophos.
    > Built Jun 6 2005 13:36:37
    > )


    Oops, I just read FAQ 5.39 :)
     
    rroo, Mar 26, 2008
    #2
    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. Brynjar Glesnes
    Replies:
    3
    Views:
    607
    Patrick TJ McPhee
    Aug 31, 2004
  2. Replies:
    1
    Views:
    406
    Fulvio
    Oct 13, 2006
  3. John Nagle
    Replies:
    4
    Views:
    615
    James Antill
    Aug 7, 2007
  4. Delaney, Timothy (Tim)
    Replies:
    0
    Views:
    581
    Delaney, Timothy (Tim)
    Aug 7, 2007
  5. Replies:
    10
    Views:
    798
    Eric Brunel
    Dec 16, 2008
Loading...

Share This Page