On Thu, Mar 17, 2005 at 09:18:45PM -0800, Larry Wall wrote:
> On Thu, Mar 17, 2005 at 06:11:09PM -0500, Aaron Sherman wrote:
> : Chop removes the last character from a string. Is that no longer useful,
> : or has chomp simply replaced its most common usage?
>
> I expect chop still has its uses.
I've had times when I wanted to be able to use chop at either
end of a string.
(I long ago suggested a "chip" operator to chop from the front of
a string. Using chip and chop on a string is much like using
shift and pop on an array.)
Generally when I do this I am not only deleting the character
from the string, but also moving it to another scaler to use;
so substr isn't a simple replacement because you'd have to
use it twice. For chip, I use (perl5):
# $ch = chip $str;
$str =~ s/(.)//;
$ch = $1;
# can be written as:
($ch) = ($str =~ s/(.)//);
If chop is removed, a similar s/// can replace it.
With the advent of rules and grammars in p6, there will likely
be less need for chip/chop type operations so this huffman
extended use of subtr instead of chip/chop would be ok.
--