Thanks to Mr. Krahn and Jaime Murilllo!

Yeeeeeee  Ha!!!!!!!

(also, a couple more ques. about the code if I may, further below)

I got the output that I want:

[EMAIL PROTECTED]:~$ grepf6tst hash
1 'hash'  array of hashes

2 'hash'  initialize sort and print hash

3 'hash'  ref deref hash array iterate

4 'hash'  hash example useage simple

xtst100805 xtst110105 xtst110805 xtst111205
1 'hashes' found in: xtst100805

2 'hash' found in: xtst110105

3 'hash' found in: xtst110805

4 'hash' found in: xtst111205

wherefound 'xtst100805 xtst110105 xtst110805 xtst111205'

enter a digit: 4
xtst111205
(data snipped)
-------------------------

I no longer need that 2nd set of numbered output.
--------------------------

#################
I still feel rather uncertain when to " " and when not to (except for when I 
need to extrapolate a scalar var's content I know how/what to do).  Any 
pointers?

#!/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;
    }
# map {print @$_} @lines; # works
# foreach (@lines) { # works
# print @$_, "\n";
# }

my $found_tally = 0;
my %data;
for my $keyline ( @lines ) {
    my $filename = shift @$keyline;
    for my $search ( @search4 ) {
        for ( @$keyline ) {
            if ( /$search/ ) {
                push @{ $data{ $filename } }, $_;
#                print ++$found_tally . " " . $search,@$keyline, "\n";


##########################
# how did I do? (looks reasonable to me. but, after all, I'm beginner)
                print ++$found_tally," '$search'  @$keyline\n\n";
                }
            }
        }
    }

my @foundin = sort keys %data;


################## most array print without wrap in " " ???
#print @foundin, "\n"; # does not print
print "@foundin\n"; # why are " " needed?


## I just now removed next section and outputs *exactly* like I want
###### would someone explain what is going on in next (2 for) block(s)?
$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>;

-- 
Alan.

-- 
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