[comp.lang.perl] Help with op.exec test

jb3o+@andrew.cmu.edu (Jon Allen Boone) (01/29/91)

Hi.  My perl compilation on a Dec3100/Ultrix 3.1 box has passed all
the tests except op.exec.  It fails on test 1 (according to make test)
and returns the following when run manually.

----- op.exec output -----
1..8
ok 1
not ok 1
ok 2
not ok 2
ok 3
not ok 3
not ok 4
not ok 5
not ok 6
ok 7
ok 8
----- op.exec output -----

My question is "what is the purpose of op.exec?"  That is to say, what
is it testing?  For instance, test 1 is:

print "not ok 1\n" if system "echo ok \\1";     # shell interpreted

why is perl not ok if a system call "echo ok \\1" works?

I'm horribly confused.  (I'm sorry if this is a simple question
aswerale by RTFMing the man pages.)


-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
| Iain | jb3o@andrew.cmu.edu | iain@stat.cmu.edu | R746JB30@VB.CC.CMU.EDU |
-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
| therion@drycas.club.cc.cmu.edu  | SNAIL MAIL:    5516 Howe Apt #2.      |
| bruhaha@anthrax.club.cc.cmu.edu |		   Pittsburgh, PA 15232   |
----------------------------------|++++++++++++++++++++++++++++++++++++++++
| "He divines remedies against injuries;   | "Words are drugs."           |
|  he knows how to turn serious accidents  |     -Antero Alli             |
|  to his own advantage; whatever does not |                              |
|  kill him makes him stronger."           | "Culture is for bacteria."   |
|                   - Friedrich Nietzsche  |     - Christopher Hyatt      |
-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

allbery@NCoast.ORG (Brandon S. Allbery KB8JRR) (01/31/91)

As quoted from <Ibd5L7a00j694d6gdN@andrew.cmu.edu> by jb3o+@andrew.cmu.edu (Jon Allen Boone):
+---------------
| My question is "what is the purpose of op.exec?"  That is to say, what
| is it testing?  For instance, test 1 is:
+---------------

The Perl features which use the exec system call.

+---------------
| print "not ok 1\n" if system "echo ok \\1";     # shell interpreted
| 
| why is perl not ok if a system call "echo ok \\1" works?
+---------------

The "system" function in Perl doesn't return true/false; it returns the
commands's exit status, which is 0 if the command *succeeded*.  So you have to
"reverse" the sense of what you're testing for, just as you must in C --- to
see if it failed, you must test for what would normally be SUCCESS.

Larry's fond of fast idioms.  A more readable (but slower) version of the test
is:

	print "not ok 1\n" unless system("echo ok \\1") == 0;

++Brandon
-- 
Me: Brandon S. Allbery			    VHF/UHF: KB8JRR on 220, 2m, 440
Internet: allbery@NCoast.ORG		    Packet: KB8JRR @ WA8BXN
America OnLine: KB8JRR			    AMPR: KB8JRR.AmPR.ORG [44.70.4.88]
uunet!usenet.ins.cwru.edu!ncoast!allbery    Delphi: ALLBERY