develooper Front page | perl.beginners | Postings from August 2009

Re: two questions

Thread Previous | Thread Next
sys adm
August 6, 2009 02:33
Re: two questions
Message ID:
I have missed a '$' in the original post.
I do hate to write s/^\s+|\s+$//g for each and each time,just got tired of it.
So I hope perl can have that a string operator, since many script languages have that, and it's used universally.


--- wrote:

From: "John W. Krahn" <>
To: Perl Beginners <>
Subject: Re: two questions
Date: Tue, 04 Aug 2009 23:24:56 -0700

sys adm wrote:
> 1. why perl doesn't have a built-in strip() function?

Why doesn't BASIC have built-in regular expressions?  Why doesn't C have 
built-in strings?  Why doesn't $LANGUAGE have built-in $FEATURE? 
Because that is the way the language was designed.

> each time I need
> to say $var =~ s/^\s+|\s+//g to strip the blank space before and after
> the variable, specially if this is a CGI var.

That actually strips *all* whitespace from the variable:

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About