On Tue, Oct 15, 2002 at 04:08:41AM +0000, Ton Hospel wrote:
> In article <[EMAIL PROTECTED]>,
> [EMAIL PROTECTED] writes:
> > En op 15 oktober 2002 sprak Aaron Mackey:
> >> @d = splice(split, -4); # I always know that the last 4 fields
> >
> > This won't compile (first argument to splice must be an array).
> >
> >> # this next line is the one to focus on:
> >> $str = join("", (split(/(\s+)/, $_, scalar(@d) + 1))[0..2*$#d]);
> >> method 2:
> >> ($str) = m/^(\S+(?:\s+\S+){$#d})/;
> >
> > @d = (split)[-4..-1]; # @d contains last 4 fields for later use
> > s/(?:\s+\S+){4}\s*$//; # $_ now contains required string
> >
> > /-\
> /\S+/g;//;//;//;// # $` now contains required string
Unfortunately, this solves the wrong problem. It gets the first four
pieces of the string, instead of all but the last four. I think this
approach would work to get the desired string in $`:
/(\s+\S+){4}\s*$/;
Ronald