Alan_C wrote:
> 
> Hi.

Hello,

> Thanks for the help.  I've got a (Linux platform) working solution with 
> the improvements that I mentioned are onto it.
> 
> When searching (enter on commandline) multiple words it can print out several 
> listings of the same xtst file due to I use some cross referencing of my 
> keywords in the xtst files.  I'd like for it to not list out a particular 
> xtst file more than once -- will see what I can do on this.

This may be close to what you want:

#!/usr/bin/perl -w
use strict;

my @search4 = @ARGV;    # keywords

@ARGV = glob 'xtst*';
my @lines;
while ( <> ) {
    if ( s/^#:// ) {
        push @lines, [ $ARGV, split ];
        }

    # quit looking when we reach the ninth line
    close ARGV if $. == 9;
    }

my %data;
for my $keyline ( @lines ) {
    my $filename = shift @$keyline;
    for my $search ( @search4 ) {
        for ( @$keyline ) {
            if ( /$search/ ) {
                push @{ $data{ $filename } }, $_;
                }
            }
        }
    }

my @foundin = sort keys %data;

my $found_tally = 0;
for my $filename ( @foundin ) {
    for ( $data{ $filename } ) {
        $_ = join "\0and\0", @$_;
        s/\0and\0(?=.*\0and\0)/, /g;
        s/\0and\0/ and /;
        print ++$found_tally, " '$_' found in: $filename\n\n";
        }
    }

print "wherefound '@foundin'\n\n";

print "enter a digit: ";
my $d = <STDIN> - 1;

print "$foundin[$d]\n";
open my $fh, $foundin[ $d ] or die "Cannot open '$foundin[$d]' $!";
print while <$fh>;

__END__



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to