maximum int value

PERL

    Next

  • 1. Getting the total size of a directory
    I'm running out of web space and want to write a script that tell me the size of certain directories so I can see where the hog is. Can anyone give me some quick code?
  • 2. large directory handling
    Hello all, I am trying empty a directory with over 4000 files with a script, and do not understand why I can only delete half at a time. I am guessing that the directory handle has a size limitation?? Is there a way to load the contents into a large array or am I going about this all wrong? Please forgive the newbie question. I'm trying to hack this with my copy of the Perl Bookshelf and limited practical experience. #!/usr/bin/perl #open directory and load contents into hash $dir = "/test/directory"; opendir(@DIR, $dir) or die "cant opendir $dir: $!"; while (defined($file = readdir(DIR))) { if ($file =~ "klee") { #matching a specific file, avoiding . & .. and .AppleDouble directory $file2 = $dir . "/" . $file; unlink($file2); print "unlinking $file2...\n"; } } closedir(@DIR); Thanks!

maximum int value

Postby alon » Wed, 28 Dec 2005 20:58:29 GMT

Is there a constant or a definition for a maximum number in perl? And
the same question for a minimum value?

Alon

Re: maximum int value

Postby fxn » Wed, 28 Dec 2005 21:48:17 GMT




You have some constants available through the %Config hash in Config.pm:

% perl -MConfig -le 'print "$_ = $Config{$_}" for grep /size$/, keys % 
Config'
charsize = 1
d_chsize =
doublesize = 8
fpossize = 8
gidsize = 4
i16size = 2
i32size = 4
i64size = 8
i8size = 1
intsize = 4
ivsize = 4
longdblsize = 16
longlongsize = 8
longsize = 4
...

So in this machine an int is 4 bytes (ivsize).

Nevertheless, Perl internally may switch to some floating-point type  
if it needs to:

% perl -MDevel::Peek -wle '$a = 1 << 31; Dump($a); $a *= 2; Dump($a)'
SV = IV(0x180cac8) at 0x1800f4c
   REFCNT = 1
   FLAGS = (IOK,pIOK,IsUV)
   UV = 2147483648
SV = PVNV(0x1803850) at 0x1800f4c
   REFCNT = 1
   FLAGS = (NOK,pNOK)
   IV = -2147483648
   NV = 4294967296
   PV = 0

and in consequence the number may look like an integer but not be  
accurate.

So this limit is well-defined in the sense of %Config, but at the  
level of Perl code the actual "type" of an integer depends on the  
implementation of the interpreter, and hence that limit has to be  
used carefully. The pragma integer adds some control:

% perl -Minteger -MDevel::Peek -wle '$a = 1 << 31; Dump($a); $a *= 2;  
Dump($a)'
SV = IV(0x180cad0) at 0x180061c
   REFCNT = 1
   FLAGS = (IOK,pIOK)
   IV = -2147483648
SV = IV(0x180cad0) at 0x180061c
   REFCNT = 1
   FLAGS = (IOK,pIOK)
   IV = 0

And, lastly, the pragma bigint removes the limit for integers in  
practice.

-- fxn


Re: maximum int value

Postby a.r.ferreira » Wed, 28 Dec 2005 21:51:09 GMT



This may work for you

the biggest unsigned integer

$ perl -e 'print ~0'
18446744073709551615 # 64-bit integers

the maximum signed integer

$ perl -MConfig -e 'print( (1<<$Config{ivsize}*8-1)-1 )'
9223372036854775807

the minimum signed integer

$ perl -MConfig -e 'print -(1<<$Config{ivsize}*8-1)'
-9223372036854775808

I am not sure how general these expressions are. The illustrated
values are for 64bit integers.

Adriano.

Re: maximum int value

Postby swayamprakash.panda » Wed, 28 Dec 2005 21:56:09 GMT

I don't think so 
----- Original Message ----- 
From: "Alon Marx" < XXXX@XXXXX.COM >
To: < XXXX@XXXXX.COM >
Sent: Tuesday, December 27, 2005 5:28 PM
Subject: maximum int value



Re: maximum int value

Postby alon » Wed, 28 Dec 2005 22:30:19 GMT

Seems like a good solution for my needs, but how do I use it in a perl
program instead of an inline command? 

For example, if I try to set a variable with such a value: 
$a = (1<<$Config{ivsize}*8-1)-1;

I get an error "Global symbol "%Config" requires explicit package name
at"

Thanks, 
Alon







Re: maximum int value

Postby security.department » Wed, 28 Dec 2005 22:44:45 GMT

Alon Marx am Dienstag, 27. Dezember 2005 14.30:

You have to import the Config module with

	use Config;

Adriano imported it in the cmd line with

	-MConfig

hth, joe


[top posting history:]




Re: maximum int value

Postby alon » Wed, 28 Dec 2005 22:46:20 GMT

Works like a charm.
Thank you all.







Similar Threads:

1.KILL INT can not wake up $SIG{INT}

Hi list,

Anyone has such experience? KILL INT pid cannot wake up $SIG{INT}  sub{}.

my code is like;

$SIG{INT} = sub {#load pm}

$SIG{ALRM} = sub {print "Driver $pm is going to sleep... bye.\n"; exit;};

the pm actually has a system call to execute something
sub xxx {
`perl xxx.pl` 
}

but  

my $tmp = kill "INT", $pid; ## it returns number of processes, eg: 1
cannot wake up the $SIG{INT}  at all after $SIG{ALRM} has been executed.

does system call cause the problem?

Thanks.

2.Storing a long value in an int

Hi,
I need to set this flag = 0x0010000
My code is as follows:

$flag = 0x0010000;
print("setting flag $flag\n");
produces: 65536
But when I say $quote-SetFlag($flag);
The flag is being set to 0;

I see that the number I am trying to set is 65536.
Is there a way I can make $flag a long int to store 65536 ?

Thanks,
Radhika


-- 
It is all a matter of perspective. You choose your view by choosing where
to stand.
Larry Wall
---

3.Storing a long value in an int [correction]

4.Using hyperlink to pass an int value using the 'Jump to URL' f

5.Using hyperlink to pass an int value using the 'Jump to URL' featu

6. Math::BigInt maximum value

7. Maximum value in Hash

8. maximum hash/array keys/values



Return to PERL

 

Who is online

Users browsing this forum: No registered users and 32 guest