amit hetawal wrote:

> Hello all,
>  here is the updated info about the problem:
> I have the file as :
>  
> <document>hello how r u <docuemnt>hi all what r u doin<document>i am
> fine<document>
>  
> Now what i have to do is to form a matrix as 
> 
>       Hello       fine   
> D1      1          1          .
> 
> D2      0          1          ; 
> 
> D3      0          0
> 
> D4      1          1        so on
>  
>  
> Hello and fine are pre defined words.
> D1 D2 D3 D4 are the ducment tags in which i have to search these words
> if the word present then have to put the value as 1 for the particular
> row and column.
> I am not getting hwo to go about for the logic. Can soebody help me with
> this.

Take this and figure out how to format the hash:

use strict;
use warnings;
use Data::Dumper; $Data::Dumper::Indent=1; $Data::Dumper::Sortkeys=1;

my @words = ('hello', 'fine');

my @data = (
  '<document>hello how r u <document>hi all what r u doin<document>i am 
fine<document>how fine r u <document>',
  '<document>hello how r u <document>hi all what r u doin<document>i am 
fine<document>how fine r u <document>');

my %hash;
foreach my $line (@data) {

        my @f = split /\s*<document>\s*/, $line;
        shift @f if not $f[0];

        my $ii = 0;
        foreach my $fld (@f) {

                foreach (@words) {
                        ++$hash{$_}[$ii] if $fld =~ /$_/i;
                }
                ++$ii;
        }
}
print Data::Dumper->Dump([\%hash], [qw(\%hash)]);

# format the hash anyway you like

__END__
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to