Perl variable "leading white spaces" Please help

Discussion in 'Perl' started by \Dandy\ Randy, Jul 20, 2003.

  1. Hello everyone. I have been following misc posts, as well as reading several
    FAQ's on this issue, unfortunatley I cannot locate a solution. I am hoping
    that someone will be able to provide me with the simple answer. My problem
    has to do with the leading white spaces after the first line when calling
    data using the @ variable. Here is my code:

    open (PREVIEW, "<preview.txt") or &error("Unable to open the data file for
    reading");
    flock PREVIEW, 2;
    @previewcontent=<PREVIEW>;
    close(PREVIEW);

    Later down the script there is this code:

    print "Content-type: text/html \n\n";
    print <<PRINTHTML;
    <html><head><title>My Script></title></head>
    <body>
    <textarea rows="5" name="headerdata" cols="50">@previewcontent</textarea>
    </body>
    </html>
    PRINTHTML
    exit;

    On most FAQ's and other support pages, this issue is usually caused by
    adding "" 's to the variable when assigning it's value ... in my case, i'm
    just opening a text file, and assigning all data to the @previewcontent
    variable ... no "" 's present. When I run the script, the open file command
    works correctly and shows the data in the textarea box, but on every line
    except the first, all lines lead off with a white space like below:

    This is the first line data
    This is the second line data
    This is the third line data
    This is the forth line data ... and so on.

    This is a big problem because below the textarea box there is a button to
    save the data back to the text file ... and it saves these whitespaces with
    it. Everytime the script loads, an additional white space is added without
    end. Please help me! I wouldnt have posted this topic unless I has searched
    everywhere I could first. Thank you to all who read and/or respond with a
    solution! Hoping to deliver a solution to my boss soon.

    TIA Randy
    \Dandy\ Randy, Jul 20, 2003
    #1
    1. Advertising

  2. \Dandy\ Randy

    Shawn Corey Guest

    "Dandy" Randy wrote:

    > Hello everyone. I have been following misc posts, as well as reading several
    > FAQ's on this issue, unfortunatley I cannot locate a solution. I am hoping
    > that someone will be able to provide me with the simple answer. My problem
    > has to do with the leading white spaces after the first line when calling
    > data using the @ variable. Here is my code:
    >
    > open (PREVIEW, "<preview.txt") or &error("Unable to open the data file for
    > reading");
    > flock PREVIEW, 2;
    > @previewcontent=<PREVIEW>;


    Add here:
    map { s/^\s+// } @previewcontent;

    > close(PREVIEW);
    >
    > Later down the script there is this code:
    >
    > print "Content-type: text/html \n\n";
    > print <<PRINTHTML;
    > <html><head><title>My Script></title></head>
    > <body>
    > <textarea rows="5" name="headerdata" cols="50">@previewcontent</textarea>
    > </body>
    > </html>
    > PRINTHTML
    > exit;
    >
    > On most FAQ's and other support pages, this issue is usually caused by
    > adding "" 's to the variable when assigning it's value ... in my case, i'm
    > just opening a text file, and assigning all data to the @previewcontent
    > variable ... no "" 's present. When I run the script, the open file command
    > works correctly and shows the data in the textarea box, but on every line
    > except the first, all lines lead off with a white space like below:
    >
    > This is the first line data
    > This is the second line data
    > This is the third line data
    > This is the forth line data ... and so on.
    >
    > This is a big problem because below the textarea box there is a button to
    > save the data back to the text file ... and it saves these whitespaces with
    > it. Everytime the script loads, an additional white space is added without
    > end. Please help me! I wouldnt have posted this topic unless I has searched
    > everywhere I could first. Thank you to all who read and/or respond with a
    > solution! Hoping to deliver a solution to my boss soon.
    >
    > TIA Randy
    >
    >
    Shawn Corey, Jul 20, 2003
    #2
    1. Advertising

  3. -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Shawn Corey <> wrote in news::

    > "Dandy" Randy wrote:
    >
    >> Hello everyone. I have been following misc posts, as well as reading
    >> several FAQ's on this issue, unfortunatley I cannot locate a
    >> solution. I am hoping that someone will be able to provide me with
    >> the simple answer. My problem has to do with the leading white spaces
    >> after the first line when calling data using the @ variable. Here is
    >> my code:
    >>
    >> open (PREVIEW, "<preview.txt") or &error("Unable to open the data
    >> file for reading");
    >> flock PREVIEW, 2;
    >> @previewcontent=<PREVIEW>;

    >
    > Add here:
    > map { s/^\s+// } @previewcontent;


    That won't solve the poster's problem, as the spaces are not in the values
    of @previewcontent, but rather added when it is interpolated into the
    string.

    - --
    Eric
    $_ = reverse sort qw p ekca lre Js reh ts
    p, $/.r, map $_.$", qw e p h tona e; print

    -----BEGIN PGP SIGNATURE-----
    Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

    iQA/AwUBPxszjmPeouIeTNHoEQKJJACcD7g855x5/wM24MTl66WC2XBcHy0AoMlh
    N/eUeI+V+lbpuyqNNXnVL6IY
    =TnWM
    -----END PGP SIGNATURE-----
    Eric J. Roode, Jul 21, 2003
    #3
    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:
    4
    Views:
    502
    Chris Uppal
    May 5, 2005
  2. KK
    Replies:
    2
    Views:
    545
    Big Brian
    Oct 14, 2003
  3. MuZZy
    Replies:
    7
    Views:
    1,740
    Mike Hewson
    Jan 7, 2005
  4. Replies:
    61
    Views:
    906
    Chris Torek
    Jun 9, 2011
  5. \Dandy\ Randy
    Replies:
    2
    Views:
    108
Loading...

Share This Page