in reply to Re^2: a farewell to chop
in thread a farewell to chop

Which, fortunately, is why we've got the marvellous \X sequence: s/\X$// will do what you want.

--
Tommy
Too stupid to live.
Too stubborn to die.

Replies are listed 'Best First'.
Re^4: a farewell to chop
by particle (Vicar) on Sep 11, 2002 at 18:29 UTC
    \X fixes the utf8 problem, but there's still a problem with this regex...

    #!/usr/bin/perl -w use strict; use utf8; my($a,$b,$c); $a=$b=$c="123\n456\n"; print chop $a; # prints "\n" print $b =~ s/\X$//; # prints "1" print $a; # prints "123\n456" print $b; # prints "123\n45\n" ## OOPS!!!
    i believe s/\X\z// will do what you want, although it still won't return the character removed. instead, use substr EXPR,OFFSET,LEN,REPLACEMENT (i.e. substr $_,-1,1,'').

    ~Particle *accelerates*