in reply to TRIM in Perl?

No, that will NOT drop the leading and trailing spaces. Only the leading spaces (you are anchored by "^").

There's no sub for trimming strings in perl. The best way is probably to just go ahead and bite the bullet:

my $temp = " Hello "; $temp =~ s/^\s+//; $temp =~ s/\s+$//;

You can write your own trim() function to automate this if you wish.

--
perl: code of the samurai

Replies are listed 'Best First'.
Re^2: TRIM in Perl?
by Aristotle (Chancellor) on Sep 10, 2002 at 16:21 UTC
    Occasionally also written as s/^\s+|\s+$//g;

    Makeshifts last the longest.

      I did some benchmarking, and I am absopositively amazed at how much faster that is than two s//'s. 3-4 times faster in my tests. Thank you very much for that one.

      --
      perl: code of the samurai