Logo

Programming-Idioms

History of Idiom 110 > diff from v6 to v7

Edit summary for version 7 by :
[Perl] Only 1 solution per impl

Version 6

2016-01-07, 19:44:44

Version 7

2016-01-08, 09:21:29

Idiom #110 Check if string is blank

Set boolean blank to true if string s is empty, or null, or contains only whitespace ; false otherwise.

Idiom #110 Check if string is blank

Set boolean blank to true if string s is empty, or null, or contains only whitespace ; false otherwise.

Code
$blank = !$s;                 # true if undefined, or empty
$blank = !$s || $s=~/^\s*$/;  # ... or just whitespace
Code
$blank = !$s || $s=~/^\s*$/;
Comments bubble
Left part catch undefined or empty.
Right part catches "whitespaces only".