Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Getting rid of first space?

by thpfft (Chaplain)
on Mar 16, 2003 at 04:21 UTC ( [id://243418]=note: print w/replies, xml ) Need Help??


in reply to Getting rid of first space?

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...

Replies are listed 'Best First'.
Re: Re: Getting rid of first space?
by Anonymous Monk on Mar 16, 2003 at 04:32 UTC
    This line took the empty spaces out:

    print MAIL join('', @messagebody);

    but if the text file looks like this:

    one. two. three, four.
    It comes out looking like this:
    one. two. three, four.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://243418]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-19 17:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found