> If I have a string and the first character is a space, > may not always be a space. > Example: John > Tommy > Beth > > John and Beth have a space, Tommy does not. > How do I strip that. I do not want to use the global > command because a want the space between First > and Last name. Any suggestions? > > Susan
I got this subroutine from a friend (who originally got it from the cookbook, I think). #this subroutine trims leading and trailing white space from a variable #it accepts either a variable or an array as its only argument sub Trim{ my @out = @_; for (@out){ s/^\s*(.*?)\s*$/$1/; } #end for return wantarray ? @out : $out[0]; } #end sub $name = " John Doe "; $name = Trim($name); print ("$name\n"); would return: John Doe So, in your case, the script would return: John Tommy Beth This routine strips the leading and trailing spaces, so it would allow you to maintain the space between the first and last name that you were worried about. Hope this helps... Jason CONFIDENTIALITY NOTICE: ************************************************************************ The information contained in this ELECTRONIC MAIL transmission is confidential. It may also be privileged work product or proprietary information. This information is intended for the exclusive use of the addressee(s). If you are not the intended recipient, you are hereby notified that any use, disclosure, dissemination, distribution [other than to the addressee(s)], copying or taking of any action because of this information is strictly prohibited. ************************************************************************