chinamox has asked for the wisdom of the Perl Monks concerning the following question:
Hello good monks!
I am finishing up an assignment that uses Markov chain algorithim to generate psuedo text. The problem is that while it is almost working, I am getting the followint message:
"Use of uninititiated value in join or string at (file location)"
I that this points to a scoping issue but I am not sure how to fix it. The code is below:
#!/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 wo +rds #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 " "; }
My thanks to anyone who can suggest a way to fix this little problem.
-mox
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Scoping Problem? - 'Use of uninititiated value...'
by GrandFather (Saint) on Nov 01, 2006 at 03:00 UTC | |
|
Re: Scoping Problem? - 'Use of uninititiated value...'
by dewey (Pilgrim) on Nov 01, 2006 at 05:37 UTC | |
by chinamox (Scribe) on Nov 06, 2006 at 01:52 UTC | |
|
Re: Scoping Problem? - 'Use of uninititiated value...'
by Anonymous Monk on Nov 01, 2006 at 03:02 UTC | |
|
Re: Scoping Problem? - 'Use of uninititiated value...'
by holcapek (Sexton) on Nov 01, 2006 at 07:14 UTC |