regex - Indexing every occurrence of a key in an array of strings with perl -
i have array of strings @sentences , trying find best way index each occurrence of every word respect line number on. thought nested loop , 2 dimensional array have had no luck.
assuming words space-delimited (adjust needed)
my $index = {}; $line=0; $s (@sentences) { $line++; $w (split $s) { push @{$index->{$w}},$line; } }
this creates hash keys words , values arrayrefs containing lists of line numbers in words appear.
Comments
Post a Comment