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. One method:
$_ = <DATA>;
@d = splice(split, -4); # I always know that the last 4 fields
# should be removed ...
# this next line is the one to focus on:
$str = join("", (split(/(\s+)/, $_, scalar(@d) + 1))[0..2*$#d]);
ok($str, "This is the string I want");
__DATA__
This is the string I want AND THIS IS BOLLOCKS
__END__
method 2:
($str) = m/^(\S+(?:\s+\S+){$#d})/;
Thanks,
-Aaron