Vous êtes sur la page 1sur 1

#!

/usr/bin/perl

#Programmed by FLJR90/FrankQC
#Simple program exercise using Regular Expressions 'regex'
#This program determines if the input is an integer or a decimal 'floating' number

use Term::ANSIColor;

system("clear");
print color 'bold red';
print "Insert a number.\n";
print color 'reset';

main();

sub main {

print "> "; chomp($x = <STDIN>);

if (! defined $x) {
print "String is not defined.\n";
main();
}elsif($x =~ /^-?\d+\.?$/) {
print "$x is an integer.\n";
main();
}elsif($x =~ /^-?\d+\.\d+$/) {
print "$x is a floating-point (decimal) number.\n";
main();
}elsif($x eq undef) {
print "String did not get an input.\n";
main();
}else{
print "The input string is: '$x'\n";
main();
}
}

Vous aimerez peut-être aussi