469,306 Members | 1,881 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

Function to check a number between a range in perl

Function to check a number between a range in perl
=========================================


Back ground:
This situation has been fixed in Perl5.005. Use of .. in a for loop will iterate over the range, without creating the entire range.

Expand|Select|Wrap|Line Numbers
  1.     for my $i (5 .. 500_005) {
  2.         push(@results, some_func($i));
  3.     }
will not create a list of 500,000 integers.

Problem:
Here is the catch, think this 'Range iterator' is used only for integers. How about numbers bigger than integers

When I tried:
Expand|Select|Wrap|Line Numbers
  1.   for my $i (9845456557 .. 9845456559) {
  2.   }
It is giving an error:
Range iterator outside integer range.

I can do it in the normal crude way, by having a 'for' loop but want to check whether any other function is there that supports my case.

Thankz in advance.
Nov 2 '07 #1
4 7918
KevinADC
4,059 Expert 2GB
This is a limitation of the system perl is running on. I do not know what the work around is though. Maybe you can use Math::Bigint
Nov 2 '07 #2
This is a limitation of the system perl is running on. I do not know what the work around is though. Maybe you can use Math::Bigint
Hello Kevin...

Thankz for the info.

Infact I could get the logic and fixed my code by using the 'for' loop

for (my $i =9845456557; $i <= 9845456559; $i++) {
}

But was wondering, what will be the difference between using the 'range iterator' and the 'for' loop. Is there any performance impact? Just curious to know!
Nov 2 '07 #3
KevinADC
4,059 Expert 2GB
I don't know if one method is more efficient than the other. My guess is that they are the same or nearly the same.
Nov 2 '07 #4
I don't know if one method is more efficient than the other. My guess is that they are the same or nearly the same.
Thankz Kevin. Appreciate your time!
Nov 5 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

9 posts views Thread by Penn Markham | last post: by
7 posts views Thread by Xah Lee | last post: by
15 posts views Thread by Xah Lee | last post: by
24 posts views Thread by Xah Lee | last post: by
10 posts views Thread by Fredrik Tolf | last post: by
5 posts views Thread by sameer_deshpande | last post: by
10 posts views Thread by kj | last post: by
10 posts views Thread by Matthias | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.