in reply to Filtering unwanted chars from input field
I agree with CountZero. One implementation of this can be:
use strict; use warnings; print filter($_), "\n" for <DATA>; sub filter { my $str = shift; defined $str or return ''; my $acceptable = 'a-z0-9_.'; $str =~ s/[^$acceptable]//gi; return $str; } __DATA__ Hello, world! te-st%$/*. All_of_this_is_OK. !@#$%^&*()12345
Output
Helloworld test. All_of_this_is_OK. 12345
Edit: Used a simpler s///
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Filtering unwanted chars from input field
by johngg (Canon) on Dec 17, 2012 at 21:02 UTC | |
by Kenosis (Priest) on Dec 17, 2012 at 21:10 UTC | |
by Anonymous Monk on Dec 18, 2012 at 14:01 UTC | |
by johngg (Canon) on Dec 18, 2012 at 14:14 UTC | |
by Anonymous Monk on Dec 19, 2012 at 20:51 UTC | |
by johngg (Canon) on Dec 19, 2012 at 23:18 UTC |
In Section
Seekers of Perl Wisdom