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:

$ perl -le'my $var = " one two three "; print "*$var*"; $var =~ s/^\s+|\s+//g; print "*$var*"'
* one   two  three *
*onetwothree*

According to the FAQ you want to do it like this:

s/^\s+//, s/\s+$// for $var;


2. what's the standard module or method to generate a random string,
for example the string will be used as part of url.

AFAIK there is no standard module but you could do something like this:

my @chars = ( 'a' .. 'z', 'A' .. 'Z', 0 .. 9 );
my $string_length = 30;

my $random_string = join '', map $chars[ rand @chars ], 1 .. $string_length;




John
--
Those people who think they know everything are a great
annoyance to those of us who do.        -- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to