How do I remove white space in a Perl string?

后端 未结 12 1899
离开以前
离开以前 2020-12-31 09:34

If I declared a variable $myString with the value \'3 \' (notice the white space). Is there any function to remove the white space for the return v

12条回答
  •  独厮守ぢ
    2020-12-31 09:53

    sub trim
    {
        my $str = $_[0];
        $str=~s/^\s+|\s+$//g;
        return $str;
    }
    
    print trim(" 4 ");
    

提交回复
热议问题