<[EMAIL PROTECTED]> wrote:
>
> Can someone hlpe me clean up this trim?
>
> Rule: remove all trailing blanks and newline/LF
>
> Do I need a chomp here somewhere?
>
> sub trim
> { my $z = $_[0];
>
>   $z =~ s/^\s+//;
>   $z =~ s/\s+$//;
>
>   return $z;
> }

Do you mean /leading/ and trailing, which is what you've coded?

How about this:

  sub trim {
    do { s/^\s+//; s/\s+$// } for my $z = shift;
    $z;
  }

  my $x = '                 xxxxxxxx              ';

  print map "<<$_>>\n", $x, trim $x;

OUTPUT

  <<                 dddddddd              >>
  <<dddddddd>>

No chomp is needed unless you have changed the input record
separator. It is normally set to "\n" which is a whitespace
character and will be removed by s/\s+$//.

HTH,

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to