Re: strict @F
authorHallvard B Furuseth <h.b.furuseth@usit.uio.no>
Tue, 25 Mar 1997 21:10:33 +0000 (22:10 +0100)
committerChip Salzenberg <chip@atlantic.net>
Tue, 25 Mar 1997 19:04:34 +0000 (07:04 +1200)
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

toke.c

diff --git a/toke.c b/toke.c
index d1c60dd..ffc6329 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -1500,12 +1500,17 @@ yylex()
                        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