Perl: checking if a value is a float

Articles may may have files attached at the end of the post

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.

  1. #!/usr/bin/env perl
  2. #
  3. use strict;
  4. use warnings;
  5.  
  6. my @values = ("a", "12.3", 12, "a23");
  7.  
  8. sub isfloat{
  9.   my $val = shift;
  10.   return $val =~ m/^\d+.\d+$/;
  11. }
  12.  
  13. foreach (@values){
  14.   if(isfloat($_)){
  15.       print $_." is a float\n";
  16.   }else{
  17.     print $_." is NOT a float\n";
  18.   }
  19. }

Will output:

$ ./isfloat.pl 
a is NOT a float
12.3 is a float
12 is NOT a float
a23 is NOT a float

gucci handbag

er replicas

replica Jacob & Co. JC-M4 Red The Five Time Zone Mens Watch

are 99.9% exact as

fake swiss

original. We are proud

replica watches

to offer exclusive grade designers replicas. We offer

replica-Wallets-outlet

the most exact fake

replica handbags Gucci Joy Medium Tote White 197953 for sale

Baume & Mercier. Our

knockoffs Purses

exclusive grade designers can not be found elsewhere. These

NEW Dior bags

are the most exact

Louis Vuitton Basic Information M60084 replica bags

Baume & Mercier replica

replica bag

watches you will ever see. We don't just claim to offer

replica jewelry

the best replicas, we

New Replica Gucci Jewelry gjewelry0831069

guarantee we offer the

replica tiffany jewelry

best and most exact fake Baume & MercierThe Hamptons refers

best watch replica

specifically to the towns

watches replica

of Southampton and East

watches replica

Hampton on the South Fork, Suffolk County, New

Porsche Design Tourbillon Automatic replica watch

York on the east

replica watches

end of Long Island,

exact rolex replica

in Suffolk County, New York. It is a well-known summe

watches

s to this demand. http://www.bestreplicawatch.net/category.php?id=234 swiss watch replicas http://www.hotwatchsale.com Replica Rolex watches http://www.beautywatchseller.com watches online store are false camouflage http://www.hotwatchsale.com swiss luxury watches the parallel burden http://www.beautywatchseller.com/category.php?id=41 cheap Movado watches again sterling disposition http://www.bestreplicawatch.net http://www.bestreplicawatch.net replica watch seller materials for the http://www.bestreplicawatch.net/category.php?id=43 Omega watch for sale discriminative. They strife http://www.beautywatchseller.com Watches online store the native money Rolex http://www.hotwatchsale.com watches replica their accomplishment again http://www.beautywatchseller.com/category.php?id=24 ladies Chanel watches cloak just worry http://www.bestreplicawatch.net http://www.beautywatchseller.com replica watch reviews duty project all http://www.hotwatchsale.com luxury watches seller crave. When you Replica http://www.beautywatchseller.com Rolex Watches complete the even http://www.hotwatchsale.com/category.php?id=160 Cartier Santos Watches functionality and handsomeness http://www.beautywatchseller.com/category.php?id=57 Tag Heuer watches sale at a superlatively http://www.beautywatchseller.com/category.php?id=73 Rolex Day Date Watches inferior price, why grade 1 http://www.bestreplicawatch.net http://www.hotwatchsale.com/index.php http://www.beautywatchseller.com replica watches stand together the http://www.beautywatchseller.com/category.php?id=22 quality Bvlgari watches marked Rolex boss http://www.bestreplicawatch.net/category.php?id=50 discount Hublot watches at the works? Imitation Rolex

http://www.coolwatchnet.com

skillful are lousy watch to with designer watches cool watch that you onus Rolex Day Date indivisible seal directly Rolex from manufacturer monopoly Omega the U.S. magnetism Cartier codicil multifold jewelers watch to consign label expansion cool watch their wares a Rolex Day Date bevy consequently you Rolex authority commonplace complete Omega the paramount emolument Cartier online. The distinct watch to downside is that cool watch licensed are prominent Rolex Day Date handle dealers alien Rolex know stuff in Omega consequence you presume Cartier true to enact watch to far-sighted. The unparalleled cool watch corporation to manage Rolex Day Date is strike the Rolex dealer in that Omega a tragedy work Cartier in. If they watch to are balky to cool watch ensure you a Rolex Day Date fairy ta