[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: new to perl
Osiris,
On Sun, Jul 30, 2000 at 02:08:13PM -0500, oguzman@stkate.edu wrote:
>
>
> I'm new to perl scripting and would like to know if someone has a quick command
> to trim a space in an input like "A " to convert to " A". I tried tr/ //d, but
> it does not work, substitution
> is not working either. THank you,
The answer to your question can be found in the perlfaq4 manpage:
How do I strip blank space from the beginning/end of a
string?
Although the simplest approach would seem to be:
$string =~ s/^\s*(.*?)\s*$/$1/;
Not only is this unnecessarily slow and destructive, it
also fails with embedded newlines. It is much faster to
do this operation in two steps:
$string =~ s/^\s+//;
$string =~ s/\s+$//;
Or more nicely written as:
for ($string) {
s/^\s+//;
s/\s+$//;
}
If you are new to perl, I suggest reading all of the perlfaqs.
Try 'perldoc perlfaq' to see a contents listing.
-Colin.