in reply to Is there a regex match for an empty string ?
Define "empty string". Consider:
use strict; use warnings; for my $str ('', ' ', '\0', "\n", undef) { print "matched '$str'\n" if $str =~ /\A\z/; }
Prints:
matched '' Use of uninitialized value $str in pattern match (m//) at C:\Users\Pet +er\Delme~~\PerlScratch\noname.pl line 8. matched '' Use of uninitialized value $str in concatenation (.) or string at C:\U +sers\Peter\Delme~~\PerlScratch\noname.pl line 8.
length may be a better test than using a regex, and clearer to the maintenance programmer.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Is there a regex match for an empty string ?
by palkia (Monk) on Mar 19, 2012 at 23:43 UTC |