Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression equivalent to chomp

Tags:

regex

perl

i have seen somewhere instead of using chomp in perl we can use some regular expression to achieve the same task. Can anyone tell what is the regular expression will meet chomp in perl

Thanks in advance

like image 688
user2163744 Avatar asked Mar 13 '13 04:03

user2163744


1 Answers

What chomp does is remove the value of $/ from the end of its argument string (or $_ if no argument). So the equivalent regex would be:

s#\Q$/\E\z##;

Note the use of other delimiter for s/// to avoid problems with the $/ variable.

However, there is no benefit to using such a regex, rather the opposite. This is a purely academic question, in my opinion.

like image 184
TLP Avatar answered Sep 21 '22 05:09

TLP



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!