Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Does Perl 5 (or 6?) need another built-in variable for the -F switch? (re)

by tye (Sage)
on Nov 02, 2006 at 16:34 UTC ( [id://581919]=note: print w/replies, xml ) Need Help??


in reply to Does Perl 5 (or 6?) need another built-in variable for the -F switch?

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        

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://581919]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-19 19:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found