in reply to string matching/replacing

One way is to build a string of characters that should be replaced and use it with tr and eval.

Hope this helps.

antirice    
The first rule of Perl club is - use Perl
The
ith rule of Perl club is - follow rule i - 1 for i > 1

Replies are listed 'Best First'.
Re: Re: string matching/replacing
by knexus (Hermit) on Sep 06, 2003 at 20:44 UTC
    How about something like this?

    $chars will just contain a list of those you want to expose, everything else is converted to an asterisk or what ever you want. You may want to keep an original as I did with $info. Then use something like $known to expose the letters as desired. Notice, I included a space in the reveal chars to match your example.

    I hope this helps :-)

    #!/usr/bin/perl -w use strict; my $info = "I am a brown icecube"; my $chars = 'a '; my $known = $info; $known =~ s/[^$chars]/\*/g; print "$info\n"; print "$known\n";