On Friday 16 June 2006 09:02, you wrote:
> On 6/16/06, Alan_C <[EMAIL PROTECTED]> wrote:
> [snip]
>
> > 1 'build'  slack build slackbuild sbuild pkg
> >
> > 2 'build'  slack build slackbuild sbuild pkg
> >
> > 3 'build'  slack build slackbuild sbuild pkg
> >
> > 4 'kernel'  slackware 2.6 kernel howto
> >
> > 5 'kernel'  kernel compile install 2.6
> >
> > 6 'build'  building a linux kernel from source
> >
> > 7 'kernel'  building a linux kernel from source
>
> [snip]
>
> > for my $keyline ( @lines ) {
> >     my $filename = shift @$keyline;
> >     for my $search ( @search4 ) {
> >         for ( @$keyline ) {
> >             if ( /$search/ ) {
> > # How to not have duplicated keyword lines?
> > # the next line I don't understand.  How to get it hash like?
> >                 push @{ $data{ $filename } }, $_; # I think this line
> > cause #                print ++$found_tally . " " . $search,@$keyline,
> > "\n"; # prints keyline 4 ea found
> >                 print ++$found_tally," '$search'  @$keyline\n\n";
>
> last;
>
> >                 }
> >             }
> >         }
> >     }
>
[ . . ]

[EMAIL PROTECTED]:~$ grepf7tst build kernel
[ snip ]
1 'build'  slack build slackbuild sbuild pkg
2 'kernel'  slackware 2.6 kernel howto
3 'kernel'  kernel compile install 2.6
4 'build'  building a linux kernel from source
4 'kernel'  building a linux kernel from source

That's acceptable (4 files, 4 digits)

I changed $found_tally to $file_tally since this is what I use to represent 
(as a digit) which file I will then choose to be printed.

I added $i to track when the same keyline is visited more than once.

Upon succesive visits to the same keyline, $file_tally does not get 
incremented.

IOW there is only to be just one increment of $file_tally for each keyline.

It works.  I suspect there likely is a more elegant way in which to achieve 
this.  But then again I also have yet more learning curve to go through too.

Thanks!!

my $file_tally = 0;
my $i;
my %data;
for my $keyline ( @lines ) {
    my $filename = shift @$keyline;
    $i = 0; # now its a fresh keyline
    for my $search ( @search4 ) {
        for ( @$keyline ) {
            if ( /$search/ ) {
                push @{ $data{ $filename } }, $_;
                ++$i; # tracks multiple visits to one keyline
#                print ++$file_tally . " " . $search,@$keyline, "\n";
# dont inc file_tally upon any successive visit to the same keyline
                $file_tally-- if $i > 1;
                print ++$file_tally," '$search'  @$keyline\n";
                last;
                }
            }
        }
    }
# end of code snippet

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