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' [EMAIL PROTECTED]";
>
> last;
>
> > }
> > }
> > }
> > }
>
> Notice that the first three matches are the same, and the word build
> occurs 3 times in that one @$keyline array. Sounds like you want to
> stop looping over [EMAIL PROTECTED] after your first match.
That definitely helps.
Except for when there are two different search words found in the *same*
keyline (it doesn't iterate or go far enough back up the nested levels so as
to get the next keyline until it exhausts all search word searches on a
particular keyline)
[EMAIL PROTECTED]:~$ !498
grepf7tst build kernel
[ snip ]
db_choice is: sl
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
5 'kernel' building a linux kernel from source
-------------------------------------------------------------------------------
(there's still only 4 files that the criteria is found in)
1 through 4 calls and then prints a particular file. But 5 calls nothing
except a bunch of uninitialized value errors.
4 and 5 I'd want concatenated into one #4 line, like so:
4 'build' 'kernel' building a linux kernel from source
> # the next line I don't understand. How to get it hash like?
> push @{ $data{ $filename } }, $_; # I think this line cause
And *now* I see that that line *is* a hash, push filename onto %data hash
And I *now* see that my problem is the print line:
print ++$found_tally," '$search' [EMAIL PROTECTED]";
But since it prints 3 separate parameters, I'm confused if it can somehow into
hash rather than print it at that point.
An alternative way to do it could be to check if a particular keyword line has
been visited more than once, and if so, concatenate the multiple search words
together as per my above example (and do not increment ++$found_tally).
I suppose I need some hints and/or additional assistance, otherwise I might
create an increment operator that I can then check to see if I've already
visited a particular keyword line and if so, concatenate the search words.
But I haven't a clue how I'd concatenate the search words before the printing
out of that keyline.
Thanks.
--
Alan.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>