Perl: checking if a value is a float
Articles may may have files attached at the end of the post
Submitted by chantra on Fri, 04/11/2008 - 09:08
While some languages offer an is_float function, Perl seems to only rely on regex.
This tutorial will show how to find if a variable contains an integer or not.
- #!/usr/bin/env perl
- #
- use strict;
- use warnings;
- my @values = ("a", "12.3", 12, "a23");
- sub isfloat{
- }
- foreach (@values){
- if(isfloat($_)){
- }else{
- }
- }
Will output:
$ ./isfloat.pl a is NOT a float 12.3 is a float 12 is NOT a float a23 is NOT a float












