Logo

Programming-Idioms

History of Idiom 137 > diff from v21 to v22

Edit summary for version 22 by dmaestro:
New Perl implementation by user [dmaestro]

Version 21

2018-06-06, 02:38:04

Version 22

2018-08-18, 21:34:50

Idiom #137 Check if string contains only digits

Set boolean b to true if string s contains only characters in range '0'..'9', false otherwise.

Idiom #137 Check if string contains only digits

Set boolean b to true if string s contains only characters in range '0'..'9', false otherwise.

Code
my $b = $s =~ /^\d*$/;
Comments bubble
Empty string will set True. Change _* to _+ to set False in this case.
Doc URL
https://perldoc.perl.org/perlrequick.html