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. (:

- tye        


In reply to Re: Does Perl 5 (or 6?) need another built-in variable for the -F switch? (re) by tye
in thread Does Perl 5 (or 6?) need another built-in variable for the -F switch? by japhy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.