my $dat0 = 'a.txt'; open (DAT, "$dat0") or die "Could not open file `$dat0'.\n"; my @all=<DAT>; close (DAT); my @words = (); my $sentences = {}; # 'word' => [ sentences that start with `word' ] foreach my $sentence (@all) { chomp ($sentence); push (@words, [ split (/[ \t]+/, $sentence) ]); my $firstWord = $words[-1]->[0]; $sentences->{$firstWord} = [] if not exists $sentences->{$firstWor +d}; push (@{$sentences->{$firstWord}}, $#words); } my @temp = ('', ''); for (my $i = 0; $i <= $#words; $i++) { push (@temp, $all[$i]); my @referencedSentences = (); foreach my $j (@{$words[$i]}) { if (($j ne "$j") || ($j ne "v")) { # I don't get this so I lea +ve it intact if (exists $sentences->{$j}) { push (@referencedSentences, $sentences->{$j}); } } } push (@temp, \@referencedSentences); } print "Done.\n";
Now, I asked him 2 simple questions for which i have waited for most of the ight, but no one answered me.
So, if you can, please answer me on 2 simple westions about this script :
1. when i'd like to find a word in @temp, i should use :
?if (exists $sentences->{$someInput}) { push (@referencedSentences1,$sentences->{$someInput});}
In reply to looking at a hash by chiburashka
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |