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 Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs