#!/opt/bin/perl -w use strict; use warnings; my %hash; my $hash; my $w1; my $w2; my @test; my $test; my @keysout; my $keysout; my $count; my $tot_counts; my $wordprecentage; my @feed; my $feed; while (<>) { # First fill the array @test with words foreach (split) { push(@test, $_); } @keysout = @test; $test = @test; #This will be useful in the next statment } my $cyc_count = 3; # set to stop the program runs out of nw or new words #First populate the data stucture while ( $cyc_count <= $test){ my $w1 = $test[0]; my $w2 = $test[1]; my $nw = $test[2]; $hash{$w1}{$w2}{total_counts}++; $hash{$w1}{$w2}{words}{$nw}++; $cyc_count++; shift(@test); } my $cyc_count2 = 3; #Make a three element long feed $keysout = @keysout; @feed = @keysout[0,1,2]; print " the Content of feed : @feed\n"; #now read values back out using an while($cyc_count2 <= $keysout){ ############## #PROBLEM likely with how I am handling these, ############## my $w1 = $feed[0]; my $w2 = $feed[1]; my $nw = $feed[2]; #retrieves a value from my @wordsList; #################### # PROBLEM HERE 'Use of uninitialized value' #################### for my $word ( keys %{ $hash{ $w1 }{ $w2 }{ words } } ) { push @wordsList, ( $nw ) x $hash{ $w1 }{ $w2 }{ words }{ $nw }; } #print the words my $random_word = @wordsList[ rand( @wordsList ) ]; print "random word: $random_word\n"; #pushing $random_word on the end of @feed push (@feed, $random_word); #shifting one element off the left side shift(@feed); $cyc_count2++; print " "; }