LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-06-2005, 04:50 PM   #1
ivanatora
Member
 
Registered: Sep 2003
Location: Bulgaria
Distribution: Ubuntu 9.10, FreeBSD 7.2
Posts: 459

Rep: Reputation: 32
Perl, integer and floats


How can I check if a number is integer (2 3 123 12122134) or float (1.2 112.56 0.3333) ?
I tried to split it at the decimal point, but the split() function doesn't work with digits (i think):
$test = $i/$n;
@fields = split (/./,$test);
And here @fields is always emty.
 
Old 04-06-2005, 04:53 PM   #2
puffinman
Member
 
Registered: Jan 2005
Location: Atlanta, GA
Distribution: Gentoo, Slackware
Posts: 217

Rep: Reputation: 31
You can split on the decimal point, however, the dot is a meta-character (it actually stands for any character at all), so it must be escaped with a backslash. Try:

Code:
@fields = split (/\./,$test);
However, you don't need to split, you can just test for a match with a regex:

Code:
if ($test ~= m/\./) {
    # test had a decimal point
} else {
    # test did not have a decimal point
}

Last edited by puffinman; 04-06-2005 at 04:55 PM.
 
Old 04-06-2005, 05:09 PM   #3
ivanatora
Member
 
Registered: Sep 2003
Location: Bulgaria
Distribution: Ubuntu 9.10, FreeBSD 7.2
Posts: 459

Original Poster
Rep: Reputation: 32
Thanks, I noticed that
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LaTeX Gurus - figures, floats, and stuff FunkyRes Linux - Software 1 08-26-2005 05:03 PM
byte swapping for floats hypnoticSpectre Programming 1 11-08-2004 10:48 PM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM
How to display formatted floats rkrijger Linux - Software 4 10-21-2003 08:52 AM
64 bit integer fahad153 Programming 9 08-26-2003 02:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration