Archive for May, 2009

Empty is not a non-digit character in Perl

Thursday, May 28th, 2009

empty is not a non-digit character “\D”
empty is not a digit character either “\d”

The wrong way to do it:


my $f;
$check = ($f =~ m/\D/ ) ? 'non-digit character' : 'assume digit';

The correct way to do it:


my $f;
$check = ($f =~ m/\d/ ) ? 'digit character' : 'assume non-digit';

References:

$ perldoc perlretut
$ perldoc perlre

VN:F [1.8.4_1055]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.4_1055]
Rating: 0 (from 0 votes)