I think the fact that the POSIX module is almost entirely XS based, makes it 
"different" and "much more dangerous" than, say, constant.pm.  The latter is 
pure-Perl, whereas the former contains the following note:

---

The POSIX module is probably the most complex Perl module supplied with the 
standard distribution. It incorporates  
autoloading, namespace games, and dynamic loading of code that's in Perl, C, or 
both. It's a great source of wisdom.

---

If in doubt, use parenthesis. :)

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of John Deighan
Sent: Wednesday, June 29, 2005 2:29 PM
To: [email protected]
Subject: Perl Constants (was RE: mystery)


At 02:55 PM 6/29/2005, Joe Discenza wrote:

Peter Eisengrein wrote, on Wed 6/29/2005 13:04

: > Can someone tell me what's going on in my script? Here it is:
: >
: > use strict;
: > use POSIX qw(INT_MAX);
: >
: > my $i = INT_MAX;
: > my $n = INT_MAX - 1000;
: > print("i = $i\n");
: > print("n = $n\n");
: >
Simply because Perl handles constants like built-in functions. When you say 
"INT_MAX - 1000", that's equivalent to "INT_MAX(-1000)". Since INT_MAX is a 
constant function, you just get the max again.

OK, that makes sense as an explanation, though it reinforces my hatred of being 
allowed to leave off the parentheses in a function call. The possibility of 
this being interpreted as a call to function INT_MAX with an argument of -1000 
seems like a huge syntactical conflict in the language. It also made me very 
wary of using the "use constant" construct, until I tried  the following:

use strict;
use constant X => 23;

my $y = X - 2;
print("y = $y\n");

To my amazement, it actually printed out "y = 21". So, using the "use constant" 
construct actually gave the correct result. In fact, I tried, just for the heck 
of it, to change the assignment to "$y = X(-2);" and got the error message "Too 
many arguments for main::X at C:\Scripts\test.pl line 4, near "2)""

So, my conclusion is that either you are wrong about the interpretation of 
"INT_MAX - 1000" (though as I said, it certainly explains the results I 
obtained), or the INT_MAX contstant in the POSIX library is implemented in a 
different (and much more dangerous) way that when I use the "use constant" 
construct.

_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to