I'd do this in reverse order, so that you aren't substituting in a space that you're later going to remove. That's just a tiny amount of extra work. If the spaces are really spaces and not tabs, you can squeeze them using tr/ //s instead of s/\s+/ /g.$checks{'data'} =~ s/\s+/ /g; # remove leading and trailing blanks $checks{'data'} =~ s/^\s+//; $checks{'data'} =~ s/\s+$//;
The common idiom for this is$checks{'regex'} = $checks{'regex'} ? $checks{'regex'} : $default;
but be sure you mean that all false values should be replaced with default. You may have meant, instead$checks{'regex'} ||= $default;
I note that regex is really expected to be a character class. It would be simple to take a real regex (qr// style) instead.exists($checks{'regex'}) or $checks{'regex'} = $default;
In reply to Re: Check user input - reimplementation
by Roy Johnson
in thread Check user input - reimplementation
by kiat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |