Perl: function to trim string leading and trailing whitespace

后端 未结 10 2089
深忆病人
深忆病人 2021-02-01 00:12

Is there a built-in function to trim leading and trailing whitespace such that trim(\" hello world \") eq \"hello world\"?

10条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-01 00:48

    Apply: s/^\s*//; s/\s+$//; to it. Or use s/^\s+|\s+$//g if you want to be fancy.

提交回复
热议问题