Re: An array like line that I do not understand

2006-06-16 Thread Alan_C
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]
 




Re: An array like line that I do not understand

2006-06-16 Thread Alan_C
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]
 




Re: An array like line that I do not understand

2006-06-16 Thread Mr. Shawn H. Corey
On Thu, 2006-15-06 at 23:31 -0700, Alan_C wrote:
> 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

See `perldoc -q duplicate`


-- 
__END__

Just my 0.0002 million dollars worth,
   --- Shawn

"For the things we have to learn before we can do them, we learn by doing them."
  Aristotle

* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is at http://perldoc.perl.org/



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




Re: An array like line that I do not understand

2006-06-16 Thread Dave Gray

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;

}
}
}
}


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.

Dave

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