dan wrote:
> Hi again,
> 
> Yet another question for you. I string (these are just examples):
> 
> 1) this.is.a.string.to.match.with
> 2) this.is.another.string.to.match.with
> 3) this.is.a.totally.different.string
> 
> Basically, what I want to be able to do, is to carry out match testing
> against them, and return just the strings that match. For example, a
> search of *.with returns strings 1 and 2
> a search of *string* returns strings 1 and 2
> a search of *a* returns all 3
> a search of *.a.* returns 1 and 3
> I think you should get the idea.
> 
> I'm no master on regex, so I'd have absolutely no idea where to
> start. All help muchly appreciated.
> 
> Dan
        Here is a little working script using grep as the search routine.
You need to escape . so if you want .a. then \.a\. would be what you enter:

#!perl -w
my @MyData = ();
@MyData = <DATA>;
printf "%-s", join(';', @MyData);
my @MySearch = ();
my $MyInp ;
while ( 1 ) {
    printf "Please enter search criteria: ";
    chomp($MyInp = <STDIN>);
    last if ( $MyInp =~ /^\^done/i );
    
    @MySearch = grep( /$MyInp/, @MyData);
    if ( scalar(@MySearch) ) {
       printf "Search Results for <%-s>:\n %-s", $MyInp, join(' ',
@MySearch);
     }else {
        printf "No search items found for search <%-s>!\n", $MyInp;
     }
 }
__DATA__
this.is.a.string.to.match.with
this.is.another.string.to.match.with
this.is.a.totally.different.string

Wags ;)


**********************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
****************************************************************


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to