I believe I mentioned this before somewhere but (probably just in the CB, actually):
BEGIN { $sep= '' }
if( '' eq $sep && 1 < @F ) {
( $sep )= /\Q$F[0]\E(.*?)\Q$F[1]\E/;
}
Sadly, although join(undef,@F) needn't emit a warning when @F contains fewer than 2 items, it does.
Yes, it still isn't perfect (but I hope it helps some). I'm sure you know where to apply the patch. $^A doesn't appear to be used (for "auto-split separator"), last I checked.
Update: I was trying to think how to wrap this nicely into a module and also that the separator needn't be the same at each point, when I decided the way to do both would be to have the module provide a routine that replaces the old @F values with the new into $_ in-place.
my $pos= 0;
for my $f ( 0..$#F ) {
pos($_)= $pos;
die if ! m/\Q$F[$f]\E/g;
$pos= pos($_) + length($G[$f]) - length($F[$f]);
substr( $_, $-[0], $+[0]-$-[0], $G[$f] );
}
pos($_)= 0;
And I'd also like a module that ties up this trick for avoiding using $& (and capturing) that is also more useful (and faster) than either so I don't have to look up the formula each time. (:
|