Scott E Robinson wrote:
> 
> 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??
> 
> A sample candidate string:    :B000:W000:M260:8:
> For each colon-delimited substring, such as :M260:, I want a count of how
> many times it's found in each target string.
> 
> Some sample target strings:
> 
> :L520:T400:C000:S000:L200:8:          <-bare numbers are possible, like
> this :8:
> :L520:T400:C000:S000:L200:8:
> :L520:T400:C000:S000:L200:24:E214:
> :L520:T400:C000:S000:M:24:E214:       <-note the :M: string, just for
> variety
> :L520:T400:C000:S000:L200:14:E214:
> :L520:T400:C000:S000:L200:14:E214:
> :L520:M260:C000:S000:L200:14:E214:    <-this should match once
> :L520:T400:M260:S000:M260:14:E214:    <-this should match twice
> :L520:T400:C000:S000:L200:14:E214:


You probably want something like this:


my $candidate = ':B000:W000:M260:8:';

my %count = map { $_ => 0 } $candidate =~ /[^:]+/g;

while ( <DATA> ) {
    for ( /[^:]+/g ) {
        $count{$_}++ if exists $count{$_};
        }
    }

print "$_: $count{$_}\n" for keys %count;

__DATA__
:L520:T400:C000:S000:L200:8:
:L520:T400:C000:S000:L200:8:
:L520:T400:C000:S000:L200:24:E214:
:L520:T400:C000:S000:M:24:E214:
:L520:T400:C000:S000:L200:14:E214:
:L520:T400:C000:S000:L200:14:E214:
:L520:M260:C000:S000:L200:14:E214:
:L520:T400:M260:S000:M260:14:E214:
:L520:T400:C000:S000:L200:14:E214:




John
-- 
use Perl;
program
fulfillment

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

Reply via email to