Thanks, Rob and Mark, but I'm pretty sure I'm trying to do something a
little different from a count hash.  Each token in the candidate string
needs to be compared separately to all the target strings, and then count
the number of matches.  So take any token out of the first string --
:M260: for example -- and count its matches against one of the target
strings, like :L520:M260:C000:S000:L200:14:E214:.  I don't think a count
hash does that??

Thanks,

Scott

Scott E. Robinson
SWAT Team
UTC Onsite User Support
RR-690 -- 281-654-5169
EMB-2813N -- 713-656-3629


                                                                                       
                                     
                      "Mark Anderson"                                                  
                                     
                      <[EMAIL PROTECTED]       To:       <[EMAIL PROTECTED]>           
                                    
                      .com>                    cc:                                     
                                     
                                               Subject:  RE: COunting the number of 
times a string matches in another       
                                                 string                                
                                     
                      03/12/03 05:27 PM                                                
                                     
                                                                                       
                                     
                                                                                       
                                     




> > The following works the same and may or may not be easier to
> > understand/maintain.
> > $tokenCount{$_} is automatically created with a value of 0 when first
> > called, and
> > then is incremented to 1, so you don't have to test or create it
yourself.
> >
> >  my @tokens = split /:/;
> >  for (@tokens) {
> >      $tokenCount{$_}++
> >  } # for
>
> Wow!  It works.  I'm not sure that's such a good thing, though.  How does
> one ditinguish, then, between 0 as a meaningful value, and a
still-undefined
> variable?

mainly:
perldoc -f exists

sometimes:
perldoc -f defined

> I think, for the sake of healthy discipline, at least, that I would
> stick with explicitly assigning a numerical value to my  variables
> before executing any other operations on them.  Implicit casts from
> undef?  Boolean--aye, any other type, Nay!

If you wrote the following (moved from above) code, then you are already
doing it.
When the if statement evaluates $tokenCount{$_}, it creates it and assigns
a
value
to it (I don't remember what the value is, but it evaluates to ""/0/false).

> > >  my @tokens = split /:/;
> > >  foreach (@tokens) {
> > >    if ($tokenCount{$_}) {
> > >      $tokenCount{$_}++;
> > >    } else {
> > >      $tokenCount{$_} = 1;
> > >    }
> > >  }



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






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

Reply via email to