akm2 has asked for the wisdom of the Perl Monks concerning the following question:

The expression is intented to trim the spaces off the front and back of a string. Example: "          Andrew Mitchell" would be trimmed to "Andrew Mitchell"

Thats not happening. Here is the code, Any advise?

               ($BKCUM_CNUM[$i]) = substr ($line, 0, 7) =~ m/^\s*(.*)\s*$/;

Replies are listed 'Best First'.
Re: Regular Expression and trimming
by Tuna (Friar) on Mar 08, 2001 at 20:59 UTC
    Right from the Cookbook:
    $string =~ s/^\s+//; $string =~ s/\s+$//;
Re: Regular Expression and trimming
by danger (Priest) on Mar 08, 2001 at 21:04 UTC

    Yes, I suggest you visit the FAQ more often -- your question, and its answer, is contained therein.

Re: Regular Expression and trimming
by arhuman (Vicar) on Mar 08, 2001 at 21:01 UTC

    $string =~ s/^\s*(.*?)\s*$/\1/;

    "Trying to be a SMART lamer" (thanx to Merlyn ;-)