On Mon, 14 Oct 2002 20:19:10 -0400 (EDT), Aaron J Mackey wrote:

>Someone have a more "perlish", elegant, or just plain faster way of doing
>something like this: split a string on white space, pop off the last 4
>fields (perhaps to be used elsewhere), and then "rebuild" the original
>string with the correct amount of intervening whitespace. 

You mean with the same amount of whitespace as before? None of the
solutions I've seen does that.

Perhaps this is one way:

        $_ = 'This is  the string I want  AND THIS IS BOLLOCKS';
        {
            my @end;
            push @end, $+[0] while/\S+/g;
            splice @end, -4;
            substr($_, pop @end) = "";
        }
        print;

No, it's not really *that* elegant. But it does put two spaces between
"is" and "the", just as in the original.

-- 
        Bart.

Reply via email to