Perl: checking if a value is an integer
Articles may may have files attached at the end of the post
Submitted by chantra on Thu, 04/10/2008 - 15:13
While some languages offer a isint function, I could not find it in perl.
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 = ("word and word", "12", 12, "a23");
- sub isint{
- }
- foreach (@values){
- if(isint($_)){
- }else{
- }
- }
will ouput:
$ ./isint.pl word and word is NOT an integer 12 is an integer 12 is an integer a23 is NOT an integer












