home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!decwrl!concert!sas!mozart.unx.sas.com!foster!sherman
- From: sherman@unx.sas.com (Chris Sherman)
- Subject: Problem with order of precedence, maybe
- Sender: news@unx.sas.com (Noter of Newsworthy Events)
- Message-ID: <sherman.712450219@foster>
- Date: Wed, 29 Jul 1992 22:50:19 GMT
- Nntp-Posting-Host: foster.unx.sas.com
- Organization: SAS Institute Inc.
- Lines: 65
-
- Consider the following code:
-
- -----------------------------------------------
- #!/usr/local/bin/perl
- if (1 & 0 != 0) { print "1\n";}
- if (0 & 1 != 0) { print "2\n";}
- if (1 & 0 != 1) { print "3\n";}
- if (0 & 1 != 1) { print "4\n";}
-
- if ((1 & 0) != 0) { print "and 1\n";}
- if ((0 & 1) != 0) { print "and 2\n";}
- if ((1 & 0) != 1) { print "and 3\n";}
- if ((0 & 1) != 1) { print "and 4\n";}
- -----------------------------------------------
-
- Besides the output, both sets of statements are similar, except for the
- ()'s on the bottom set.
-
- According to the perl book, '&' comes before '!=', so theoretically, what
- numbers between 1-4 get hit should result in the same numbers getting hit
- on the second set of statements.
-
- The result of the routine above is:
-
- 3
- and 3
- and 4
-
- So or order of precedence is not being perserved, or I have misinterpreted
- the book, or something else really odd is going on.
-
- I'm using perl 4.0 patchlevel 35 on HP/UX, all tests passed with colors.
-
- Please help!
-
- Thanx!!!
-
- ps. This error comes from the program posted recently called bcast by
- Ed Mooring (mooring@tymix.tymnet.com). In it, he checks for compliant
- hostnames using the following section.
-
- # change inet address to match your site
- if ($inetaddr != 0x7f000001 && $inetaddr & 0xffff0000 != 0x83920000)
- {
- #
- # not a host we like, bounce it.
- #
- close ($newsock);
- if ($verbose)
- {
- $hostname = gethostbyaddr($addr, 2);
- printf "Connection refused from $hostname %x %d\n", $inetaddr, $port;
- }
- }
-
-
- Well, the results were wrong, it accepted some which it shouldn't have,
- and reject others which it should have accepted. So I wrote the test program
- above and saw that he also assumed '&' had higher precedence than '!='.
-
- --
- ____/ / / __ / _ _/ ____/
- / / / / / / / Chris Sherman
- / ___ / _/ / /
- _____/ __/ __/ __/ _\ _____/ _____/ sherman@unx.sas.com
-