home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / perl / 5899 < prev    next >
Encoding:
Internet Message Format  |  1992-09-12  |  1.5 KB

  1. Path: sparky!uunet!dtix!darwin.sura.net!sgiblab!daver!zorch!tandem!Tandem.com!sylvia
  2. From: sylvia@Tandem.com (Sylvia Tom)
  3. Newsgroups: comp.lang.perl
  4. Subject: usersub problems when invoked within a subroutine
  5. Message-ID: <1992Sep11.201054.1512@tandem.com>
  6. Date: 11 Sep 92 20:10:54 GMT
  7. Sender: news@tandem.com
  8. Organization: Tandem Computers
  9. Lines: 50
  10. Nntp-Posting-Host: moe.cpd.tandem.com
  11.  
  12. Keywords: usersub
  13.  
  14. Thanks for posting the notes on how to hook in usubs.
  15. I've compiled ex1.c on a sun workstation and found
  16. the following problem.  If I call opie from within 
  17. a subroutine and the subroutine returns a list,
  18. the resulting information returned is lost.  If,
  19. I put parenthesis around $new in the call to opie,
  20. eg ($new) = &opie($num), the script runs as
  21. expected.  Do you know why this is behaving this way?
  22.  
  23. Thanks,
  24. sylvia
  25. sylvia@tandem.com
  26.  
  27.  
  28. sub getval
  29. {
  30.    local ($num) = @_;
  31.    print "number entered is $num \n";
  32.    $new =&opie($num);
  33.    print "new = $new \n";
  34.    local ($buf) = "hi there ";
  35.    local($res) = 1;
  36.    return ($new,$buf,$res);
  37. } #===============================================
  38. if ( defined(&opie) ) {
  39.     print "&opie is defined\n";
  40.     print "\t&opie(10) = ", &opie(10), "\n";
  41. } else {
  42.     print "&opie is not defined\n";
  43. }
  44.  
  45.  
  46. ($val,$buffer,$result) = &getval (5);
  47. print "val = $val \n";
  48. print "buffer = $buffer \n";
  49. print "result = $result \n";
  50. #===================================================
  51.  
  52. #resulting output ->
  53.  
  54. &opie is defined
  55.     &opie(10) = 101.20000000000000284
  56. number entered is 5 
  57. new = 26.199999999999999289 
  58. val = 1 
  59. buffer =  
  60. result =  
  61.  
  62.