in reply to Re: find words around a word in a file.
in thread find words around a word in a file.
Furthermore looking for non-whitespace and non-punctuation could help practically solving the "what is a word problem".
Output:my %hash; $whitespace=" \n\t"; $punctuation=".,!?"; $non_delimiters="[^$whitespace$punctuation]"; while (<DATA>) { push @{$hash{$1}}, $2 while m/($non_delimiters+)\s+going\s+($non_del +imiters+)/g; } use Data::Dumper; print Dumper \%hash; __DATA__ I am going home. I am going to bed. What's going on?
I'm still not sure if a hash should be used at all, IMHO an array of pairs (two elemnet arrays) is better.$VAR1 = { 'What\'s' => [ 'on' ], 'am' => [ 'home', 'to' ] };
|
---|