On 10-06-16 06:02 PM, Greg J wrote:
Hi everyone,

I am new to Perl and I am having some trouble working with hashes of hashes.

I am trying to write a simple Markov Chain text generator and thought
it might be a good idea to keep track of state transitions in a hash.

Here is some of the code I have..

Always put these at the beginning of your scripts:

use strict;
use warnings;

What I want is this:

$VAR1 = {
           'Hello' =>  {
                        'World' =>  1
                        'There' =>  1
                      }
         };

I am looking forward to hearing all your comments.

#!/usr/bin/perl

use strict;
use warnings;

use Data::Dumper;

# Make Data::Dumper pretty
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent   = 1;

# Set maximum depth for Data::Dumper, zero means unlimited
local $Data::Dumper::Maxdepth = 0;

my %StateTable = ();

sub InsertWord
{
  my( $state, $next ) = @_;
  $StateTable{$state}{$next}++;
}

InsertWord( "Hello", "World" );
InsertWord( "Hello", "There" );

print Dumper(\%StateTable);

__END__


--
Just my 0.00000002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

The secret to great software:  Fail early & often.

Eliminate software piracy:  use only FLOSS.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to