Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!van-bc!ubc-cs!phillips From: phillips@cs.ubc.ca (George Phillips) Newsgroups: comp.lang.perl Subject: bug in !~ returning array Summary: perl -e 'print "foo" !~ /f/;' == 1 Message-ID: <6767@ubc-cs.UUCP> Date: 13 Feb 90 11:04:01 GMT Sender: news@cs.ubc.ca Reply-To: phillips@cs.ubc.ca (George Phillips) Organization: UBC Department of Computer Science, Vancouver, B.C., Canada Lines: 29 It seems that when perl does the wrong thing when it executes the !~ operator and the evaluator expects it to return an array. Running perl -e 'print "foo" !~ /f/;' gives "1" while perl -e 'print !("foo" !~ /f/);' gives "1" as well(!) The following fragment from eval.c should do something to "NOT" the array if gimme == G_ARRAY. case O_NMATCH: sp = do_match(str,arg, gimme,arglast); if (gimme == G_ARRAY) goto array_return; /* forgot to put the ! in !~ */ str_sset(str, str_true(str) ? &str_no : &str_yes); STABSET(str); break; I guess you could either set the number of elements to 0 if there are any and set the number to 1 if there aren't. Actually, does returning an array for !~ make any sense? False would be good enough if you matched, but what do you return when you don't match? A partial match based on the longest substring that matched? George Phillips phillips@cs.ubc.ca {alberta,uw-beaver,uunet}!ubc-cs!phillips -- I told him that I was a flop with scripts I've been this way since 1986 He stretched out his palm and he made a magic sign He said "What you need, boy, is patch level #9"