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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With