Regex equivalent chomp

I saw somewhere instead of using chomp in perl, we can use some regular expression to achieve the same task. Can anyone tell what a regex would be would match chomp in perl

Thanks in advance

+5
source share
2 answers

What it chompdoes is remove the value $/from the end of the argument line (or $_if there is no argument). So the equivalent regular expression would be:

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

Note the use of a different delimiter for s///, to avoid variable problems $/.

, . , .

+10

995 1000 ( ),

s/\s+\z//;

chomp;

( ), Windows UNIX.

+5

All Articles