According to Chip Salzenberg:
> sprintf( tmpbuf1, "@F=split('%s');", splitstr );
Oh, that reminds me: Splits like perl -F"/" and perl -F",'" fail.
Of course, these might be considered user errors since they conflict
with the -F doc. However, the -F doc is incorrect anyway: It says that
the pattern will be quoted unless it is *surrounded* by the delimiter.
Perl uses quotes if it *starts* with the delimiter. Which is sometimes
better because it allows options: -F/foo/i.
Anyway, here is a fix. 1st part allows things like `-F/' according to
the doc. 2nd part, if you want it, (attempts to) allow -F",'" in
conflict with the doc, which implies -F",'" is an error.
BTW, note that it's too late to obey the current doc exactly.
That would forbid options (-F/foo/i) or expressions (-F'"" + $i++').
Currently, these work - and might be in use somewhere.
p5p-msgid:
199703252110.WAA16038@bombur2.uio.no
GvIMPORTED_AV_on(gv);
if (minus_F) {
char tmpbuf1[50];
- if ( splitstr[0] == '/' ||
- splitstr[0] == '\'' ||
- splitstr[0] == '"' )
+ if ( (splitstr[0] == '/' ||
+ splitstr[0] == '\'' ||
+ splitstr[0] == '"' ) &&
+ strchr( splitstr+1, splitstr[0] ) )
sprintf( tmpbuf1, "@F=split(%s);", splitstr );
- else
- sprintf( tmpbuf1, "@F=split('%s');", splitstr );
+ else {
+ s = "'~#\200\1'"; /* surely one char is unused...*/
+ while (s[1] && strchr(splitstr, *s)) s++;
+ sprintf( tmpbuf1, "@F=split(%s%c%s%c);",
+ "q" + (*s == '\''), *s, splitstr, *s );
+ }
sv_catpv(linestr,tmpbuf1);
}
else