Zentara wrote:
>
> On Wed, 04 Jun 2003 10:55:40 +1000, [EMAIL PROTECTED] (Paul
> Morris) wrote:
>
> >I found this at:
> >
> >http://www.suse.com/us/private/support/howto/secprog/secprog8.html
> >
> >...but am having difficulty working it out, because it doesn't seem to
> >do what I think it should (and "I" may be the problem!).
> >
> >To quote:
> >--------------------
> >The best solution is to select a filter for Perl, just like for shell,
> >which only accepts authorized characters.
> >
> >unless($userinput =~ tr/[EMAIL PROTECTED]//)
> >{
> > print "Nice try, pal!\n";
> > exit(1);
> >}
>
> While playing around with this, I noticed that tr won't
> convert to nothing. Maybe that should be a space?
In this context it is not being used to convert characters, it is being
used to count characters.
> Or probably they meant s instead of tr?
>
> Anyways, I came up with this to do what they intended?
> ##########################################################
> #!/usr/bin/perl
> use strict;
>
> foreach my $inputString (<DATA>){
> chomp $inputString;
> print "$inputString-> ";
> $inputString =~ s/[EMAIL PROTECTED]//g;
That doesn't match the same characters as tr/[EMAIL PROTECTED]// does. '['
and ']' define a character class in s/// and m// but in tr/// they just
match the characters '[' and ']'. The person that wrote the referenced
web site probably had the same misunderstanding.
> print "$inputString-> ";
> if((length $inputString) == 0){print "GOOD\n"}else{print "BAD\n"}
> }
> __DATA__
> !#$%^**()
> [EMAIL PROTECTED]
> #gh#$HJ99
> Abc99dEgg
> #############################################################
>
> As far as tr goes, substitute this line in the above script,
> and run it translating to // versus / /. It refuses to translate to
> //.
>
> $inputString =~ tr/[EMAIL PROTECTED]//; #won't work
> $inputString =~ tr/[EMAIL PROTECTED]/ /; #works
If you want to delete characters with tr/// then use the /d option.
$inputString =~ tr/a-zA-Z0-9@//d;
perldoc perlop
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]