[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

How to know whtether a variable is Integer, float or a string

Posted on 2000-01-18
6
Medium Priority
?
201 Views
Last Modified: 2010-03-05
Hello there,
        It seems very stupid but I am facing problem with it. I am using a subroutine which retunrs either a string or an errorcode( a signed integer ) depends on the context. The problem for me is after getting the result from subroutine I have to format varius things depends on the value that I receive. if it is a string I will presents a form or else I have to tell vaious err.states.
            Speaking otherwords I have to seggreate Integers and String form ret. value from f a subroutine.
Thanks
Shivaki
0
Comment
Question by:shivaki
  • 3
  • 3
6 Comments
 
LVL 3

Accepted Solution

by:
guadalupe earned 0 total points
ID: 2362524
To test if something is an integer use:

if ($value =~ /^[+-]?\d+$/)
{
    #$value is an integer
}
0
 

Author Comment

by:shivaki
ID: 2362621
Thanks guadalupe ,
          This is working fine. since it is a regular expr. it has to check each and every chanracter. the other way to tackle my problem is whenever I revceives a string its length is more than 50 chars. So I think the perf. can be slighly increased based the lenght of return value. Could you please tell how to find the length of a string without using reg expr. I am not getting any strlen() function in perl.
Thanks a lot
-shivaki
0
 
LVL 3

Expert Comment

by:guadalupe
ID: 2362683
$num_of_chrs = length($value);
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:shivaki
ID: 2362720
Thanks guadalupe ,
          This is working fine. since it is a regular expr. it has to check each and every chanracter. the other way to tackle my problem is whenever I revceives a string its length is more than 50 chars. So I think the perf. can be slighly increased based the lenght of return value. Could you please tell how to find the length of a string without using reg expr. I am not getting any strlen() function in perl.
Thanks a lot
-shivaki
0
 
LVL 3

Expert Comment

by:guadalupe
ID: 2362739
Just in case you missed this comment I'll put it again:

$num_of_chrs = length($value);
0
 

Author Comment

by:shivaki
ID: 2363033
Thanks a lot!.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question