Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!newstop!exodus!snave.Eng.Sun.COM!matt From: matt@snave.Eng.Sun.COM (Matt Evans) Newsgroups: comp.lang.perl Subject: new user findings Message-ID: <13850@exodus.Eng.Sun.COM> Date: 23 May 91 00:01:41 GMT Sender: news@exodus.Eng.Sun.COM Reply-To: matt@snave.Eng.Sun.COM (Matt Evans) Distribution: na Organization: Sun Microsystems, Inc. Mt. View, Ca. Lines: 144 Hello Perl users; I've just started using perl (perl 4.0 on SUNOS 4.1.1 sun4c) and I have some questions relating to the following problems I seen ... ======================= 1) caller command: ======================= PERL core dumps on the following code: #!/usr/local/bin/perl #--------------------------- # start test (caller) main #--------------------------- $prog_dir = "./"; $prog_name = "not_here"; open (ERR_LOG,">./perr"); $proc_name = join ("",$prog_dir,$prog_name); if (!( -e $conv_proc_name)) { &conv_err ("can't access the program",1); } sub conv_err { local($err_msg,$err_code) = @_; # sub arguments # # local variable declaration # local($pack); local($file); local($line); local($sub_name); # # after debugging the core file, it seems perl # dies on the next line # ($pack,$file,$line,$sub_name) = caller (0); if ($err_code == $FATAL_ERR) { print ERR_LOG "\n\n ERROR:$pack:$sub_name:$file:$line"; die "exit test tool"; } else { print ERR_LOG "\n\n ERROR:$pack:$sub_name:$file:$line"; } } ================================ 2) numeric & string equalities ================================ In reading the camel book, it seems there should be no problem in comparing strings and numbers, However the behavior of the following perl code seems inconsistent: #!/asdf/bin/perl $x = "test"; if ($x == 0) { print "x is equal to 0\n"; } if ($x eq "test") { print "x is equal to the str \"test\"\n"; } ------------------------------------------ output: x is equal to 0 x is equal to the str "test" Question: Why does $x compare equally to numeric 0? Is this correct behavior? ================================ 3) tom christiansen's open2.pl ================================ This is more of a question and a FYI. I was using the open2.pl routine to fire off a process from perl. The routine works like a champ, but it has an interesting side effect. This side effect actually occurs in the spawned process. The spawned process I was running does an fstat on STDIN to tell if it has been started interactively from a terminal or if it has been spawned using pipes. (this C program does many things differently based on whether it is started from pipes or a character device). C code snipit: if ((sbuf.st_mode & S_IFMT) == S_IFCHR) { input_term = TRUE; } else { input_term = FALSE; } well, if the process is started from perl using open2.pl the process thinks it was started from a terminal i.e from above the var input_term is assigned to TRUE. I wrote C program to emulate open2.pl with the sequence of using pipe,fork then exec. The above process did in fact register that it is NOT started from a terminal and the C statement (sbuf.st_mode & S_IFMT) is actually equal to S_IFIFO. This is also true if a process is started from the sh pipe ('|') . So the question goes to all the perl internals wizards: Is there any hidden things happening with PERL's pipe, fork and exec commands that would explain the results I'm getting from that fstat routine on the spawned program? thanks in advance for helpin' a perl neophyte! Matt Evans