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

In reply to Scoping Problem? - 'Use of uninititiated value...' by chinamox

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.