home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / perl / 5029 < prev    next >
Encoding:
Text File  |  1992-07-29  |  2.3 KB  |  77 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!decwrl!concert!sas!mozart.unx.sas.com!foster!sherman
  3. From: sherman@unx.sas.com (Chris Sherman)
  4. Subject: Problem with order of precedence, maybe
  5. Sender: news@unx.sas.com (Noter of Newsworthy Events)
  6. Message-ID: <sherman.712450219@foster>
  7. Date: Wed, 29 Jul 1992 22:50:19 GMT
  8. Nntp-Posting-Host: foster.unx.sas.com
  9. Organization: SAS Institute Inc.
  10. Lines: 65
  11.  
  12. Consider the following code:
  13.  
  14. -----------------------------------------------
  15. #!/usr/local/bin/perl
  16. if (1 & 0 != 0) { print "1\n";}
  17. if (0 & 1 != 0) { print "2\n";}
  18. if (1 & 0 != 1) { print "3\n";}
  19. if (0 & 1 != 1) { print "4\n";}
  20.  
  21. if ((1 & 0) != 0) { print "and 1\n";}
  22. if ((0 & 1) != 0) { print "and 2\n";}
  23. if ((1 & 0) != 1) { print "and 3\n";}
  24. if ((0 & 1) != 1) { print "and 4\n";}
  25. -----------------------------------------------
  26.  
  27. Besides the output, both sets of statements are similar, except for the
  28. ()'s on the bottom set. 
  29.  
  30. According to the perl book, '&' comes before '!=', so theoretically, what
  31. numbers between 1-4 get hit should result in the same numbers getting hit
  32. on the second set of statements.
  33.  
  34. The result of the routine above is:
  35.  
  36. 3
  37. and 3
  38. and 4
  39.  
  40. So or order of precedence is not being perserved, or I have misinterpreted
  41. the book, or something else really odd is going on.
  42.  
  43. I'm using perl 4.0 patchlevel 35 on HP/UX, all tests passed with colors.
  44.  
  45. Please help!
  46.  
  47. Thanx!!!
  48.  
  49. ps.  This error comes from the program posted recently called bcast by 
  50. Ed Mooring (mooring@tymix.tymnet.com).  In it, he checks for compliant
  51. hostnames using the following section.
  52.  
  53. # change inet address to match your site
  54. if ($inetaddr != 0x7f000001 && $inetaddr & 0xffff0000 != 0x83920000)
  55. {
  56.     #
  57.     # not a host we like, bounce it.
  58.     #
  59.     close ($newsock);
  60.     if ($verbose)
  61.     {
  62.     $hostname = gethostbyaddr($addr, 2);
  63.     printf "Connection refused from $hostname %x %d\n", $inetaddr, $port;
  64.     }
  65. }
  66.  
  67.  
  68. Well, the results were wrong, it accepted some which it shouldn't have, 
  69. and reject others which it should have accepted.  So I wrote the test program
  70. above and saw that he also assumed '&' had higher precedence than '!='.
  71.  
  72. -- 
  73.      ____/     /     /     __  /    _  _/    ____/
  74.     /         /     /     /   /      /     /          Chris Sherman
  75.    /         ___   /        _/      /          /
  76.  _____/   __/   __/   __/ _\    _____/   _____/           sherman@unx.sas.com
  77.