入力文字列サニタイズの一例

送られてきた値が期待した値かどうかを調べる方法の一例。

my $posted = 'values';
$sanitized = { map { $_=>$_ } qw(list of expected values) }->{$posted};
print $sanitized; #prints "values";

my $posted = 'polluted';
$sanitized = { map { $_=>$_ } qw(list of expected values) }->{$posted};
print $sanitized; #contains undef

Leave a Reply