John wrote:
Is there any trim function that trims the spaces before and the end
of the string?
Not built-in in the Perl compiler. But you can use your own; I'm using
this for instance:
sub trim {
for ( grep defined, @_ ) {
s/^\s+//;
s/\s+$//;
}
@_ > 1 ? @_ : $_[0]
}
Assuming you have
my $string = ' some text ';
it allows you to just say:
trim($string);
to remove the whitespace at the beginning and the end. You can also do
my $trimmedstring = trim(' some text ');
If you pass a variable to the function like this:
my $trimmedstring = trim($string);
both the variables get trimmed. That's how I like it, you may prefer
it some other way.
The function can also handle multiple strings:
my @array = (' some text ', ' some more text ');
trim(@array);
HTH
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>