It sounds like something in your script is setting $, to a space, for some reason. Perhaps you're trying to print something out nicely somewhere else? Well, don't :)

Anyway, it's the print statement that's inserting the spaces, i think. The reason they show up the way they do is because each item in your array still has a newline on the end, and the space is added after that.

you have two immediate options: you can take more control over the formatting of the list with something like this:

print join('', @messagebody);

or you could save yourself lots of trouble, sort out the thing with $, and get rid of the newline character at the first opportunity:

chomp( my @messagebody = <DATA> ); print join("\n", @messagebody);

The explanation of why chomping that whole statement happens to chomp the items in the array is worth coming back to later. Meanwhile, to answer the question you actually asked, there are (at least) dozens of ways of removing the first character of each item in a list. This is the first that comes to mind:

s/^\s+// for @messagebody;

which will remove all leading spaces and tabs, and might do unkind things to, for example, messages containing python code...


In reply to Re: Getting rid of first space? by thpfft
in thread Getting rid of first space? by jimmybeaches

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.