my @arr = ( This has a leading space, This does not );
foreach my $string (@arr ) {
$string =~ s/^\s//;
print $string, \n;
}
prints:
This has a leading space
This does not
The regular expression
s/^\s//;
means
s/ # substitute
^ # at the beginning of the string
\s
Tanton Gibbs [[EMAIL PROTECTED]] quoth:
*
*The regular expression
*s/^\s//;
s/^\s+//g; would be even better as it would remove all whitspace at the
beginning of a line and it would replace all matches to the pattern
instead of just the first it finds.
e.
--
To unsubscribe, e-mail: [EMAIL
$string =~ s/^\s+//; Removes leading whitespaces
$string =~ s/^\s+//g; /g (GLOBALLY) is redundant in the
case of leading whitespages
See PERL Cookbook page 30 for the answer to your question.
__
William Ampeh (x3939)
Federal Reserve Board
If I have a string and the first character is a space,
may not always be a space.
Example: John
Tommy
Beth
John and Beth have a space, Tommy does not.
How do I strip that. I do not want to use the global
command because a want the space between First
and
[EMAIL PROTECTED] [[EMAIL PROTECTED]] quoth:
*
*$string =~ s/^\s+//; Removes leading whitespaces
*
*$string =~ s/^\s+//g; /g (GLOBALLY) is redundant in the
*case of leading whitespages
For a beginner, it's a not a critical detail.
e.
--
To unsubscribe,