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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -