in reply to trimming space from both sides of a string

That doesn't work if the string non-space characters start with something that's not a word character:
$ perl -wE '$_ = " - - "; s/^\s*\b(.*)\b\s*$/$1/g; say qq["$_"]' " - - "

In general I prefer working over interesting solutions :-). Mine:

use v6; say ' - - '.trim.perl;
Perl 6 - links to (nearly) everything that is Perl 6.

Replies are listed 'Best First'.
Re^2: trimming space from both sides of a string
by yorfeix (Novice) on Oct 12, 2010 at 12:13 UTC

    Why not use something like:

    $string =~ s/^\s+|\s+$//g;

    That should cut spaces from start and end and leave the rest.

      That's what I always use too. It does what you want (trim leading and trailing spaces), does it well, and does it without being too obscure what it is doing. I see no reasons to complicate this.

Re^2: trimming space from both sides of a string
by szabgab (Priest) on Oct 12, 2010 at 12:04 UTC
    Oh, so not only is that interesting it is also wrong :).

    Or at least I did not understand what it was doing.