473,569 Members | 2,721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Function to check a number between a range in perl

10 New Member
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 8363
KevinADC
4,059 Recognized Expert Specialist
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
Aaryan123
10 New Member
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 Recognized Expert Specialist
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
Aaryan123
10 New Member
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

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

Similar topics

9
4940
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my webserver runs that part of the script (see attached file, snippet.php), though, it doesn't go through. I don't get an error message or...
7
3302
by: Xah Lee | last post by:
Today we'll be writing a function called Range. The Perl documentation is as follows. Perl & Python & Java Solutions will be posted in 48 hours. This is Perl-Python a-day. See http://xahlee.org/web/perl-python/python.html Xah xah@xahlee.org
15
2650
by: Xah Lee | last post by:
Here's the belated Java solution. import java.util.List; import java.util.ArrayList; import java.lang.Math; class math { public static List range(double n) { return range(1,n,1); }
24
2574
by: Xah Lee | last post by:
What is Expresiveness in a Computer Language 20050207, Xah Lee. In languages human or computer, there's a notion of expressiveness. English for example, is very expressive in manifestation, witness all the poetry and implications and allusions and connotations and dictions. There are a myriad ways to say one thing, fuzzy and warm and...
10
1979
by: Fredrik Tolf | last post by:
If I have a variable which points to a function, can I check if certain argument list matches what the function wants before or when calling it? Currently, I'm trying to catch a TypeError when calling the function (since that is what is raised when trying to call it with an illegal list), but that has the rather undesirable side effect of...
21
2316
by: Dmitry Anikin | last post by:
I mean, it's very convenient when default parameters can be in any position, like def a_func(x = 2, y = 1, z): ... (that defaults must go last is really a C++ quirk which is needed for overload resolution, isn't it?) and when calling, just omit parameter when you want to use defaults: a_func(, , 3)
5
5941
by: sameer_deshpande | last post by:
Hi, I need to create a partition table but the column on which I need to create a partition may not have any logical ranges. So while creating or defining partition function I can not use any range. like CREATE PARTITION FUNCTION my_part_func (NUMERIC(7)) AS RANGE LEFT FOR VALUES (1,100,1000);
10
1159
by: kj | last post by:
Hi. I'd like to port a Perl function that does something I don't know how to do in Python. (In fact, it may even be something that is distinctly un-Pythonic!) The original Perl function takes a reference to an array, removes from this array all the elements that satisfy a particular criterion, and returns the list consisting of the...
10
4517
by: Matthias | last post by:
Dear newsgroup. I want to write a template function which accepts either integer or floating point numbers. If a certain result is not a whole number and if the template parameter is an integer, it should return false, but it should work normally if the parameter is a float. To illustrate this, I attached a minimal example.
0
7695
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8119
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7668
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6281
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.