$ ./6.markov.pl markov sub_dir is markov path1 is /home/bob/Documents/meditations path2 is /home/bob/Documents/meditations/markov out_file is /home/bob/Documents/meditations/markov/my_data/22-03-2019-13-37-35/22-03-2019-13-37-35.1.txt -------system out--------- I, the narrator, have endured many adventures in my life, but I really thought it was all prettymuch random. That the universe were deterministic never really occured to me. I love to throw the toy with the dog! When I throw with my left hand, I try to follow through with extension. Sometimes I repeat with the undef hand. You never know when the toy will take a big bounce, so I keep it low. It went south to the fence. Then my pretty pitty retrieved it at a gallop. .3 of the time I go to the gym. I perform swimming for my health. ---------------- out_file is /home/bob/Documents/meditations/markov/my_data/22-03-2019-13-37-35/22-03-2019-13-37-35.2.txt -------system out--------- I, JAPH, have endured many Bedraengnisse in my life, but I really thought it was all prettymuch random. That the universe were deterministic never really occured to me. I love to throw the toy with the dog! When I throw with my right hand, I try to follow through with extension. Sometimes I repeat with the undef hand. You never know when the toy will take a big bounce, so I keep it low. It went west. Then my pretty pitty retrieved it at a gallop. 50 percent of the time I go to the gym. I perform swimming for my health. #### #!/usr/bin/perl -w use 5.011; use Path::Tiny; use utf8; use open OUT => ':utf8'; use Data::Dump; use Text::Template; use POSIX qw(strftime); binmode STDOUT, 'utf8'; my ($sub_dir) = $ARGV[0]; say "sub_dir is $sub_dir"; my $path1 = Path::Tiny->cwd; say "path1 is $path1"; my $path2 = path( $path1, $sub_dir ); say "path2 is $path2"; ## populate hash my $data = [ [ 'protaganist', 'al debaran', 'the narrator', 'JAPH', 'gilligan'], [ 'trials' ,'adventures', 'Bedraengnisse'], [ 'ball','toy', 'object'], [ 'orientation' , 'left', 'right'], [ 'dog' ,'my pretty pitty'], [ 'num1', '.7', '.3', '50 percent'], [ 'activity', 'stretching', 'swimming'], [ 'non_orientation', 'undef'], [ 'direction', 'south to the fence', 'west', 'yonder' ] ]; #dd $data; ## main loop # set trials my $trials = 30; my $dummy = 1; while ($trials > 0){ # create an output file my $first_second = strftime( "%d-%m-%Y-%H-%M-%S", localtime ); my $out_file = $path2->child( 'my_data', "$first_second", "$first_second\.$dummy.txt")->touchpath; say "out_file is $out_file"; my %vars = map { $_->[0],$_->[rand($#{$_}) + 1] } @{$data}; my $rvars = \%vars; my @pfaden = $path2->children(qr/\.txt$/); @pfaden = sort @pfaden; #say "paths are @pfaden "; for my $file (@pfaden) { #say "default is $file"; my $template = Text::Template->new( ENCODING => 'utf8', SOURCE => $file, ) or die "Couldn't construct template: $!"; my $result = $template->fill_in( HASH => $rvars ); $out_file->append_utf8($result); } say "-------system out---------"; system("cat $out_file"); say "----------------"; $trials -= 1; $dummy += 1; } # end while condition __END__ #### $ ./3.mm.pl hoops sub_dir is hoops path1 is /home/bob/Documents/meditations path2 is /home/bob/Documents/meditations/hoops out_file is /home/bob/Documents/meditations/hoops/my_data/22-03-2019-16-09-08/22-03-2019-16-09-08.1.txt pairs are 1.duke vs 16.ndST 8.vcu vs 9.ucf 5.msST vs 12.lib 4.vaTech vs 13.stlouis 6.maryland vs 11.belmont 3.lsu vs 14.yale 7.louisville vs 10.mn 2.miST vs 15.bradley pairs are 1.duke vs 16.ndST matched 1 duke 16 ndST { event => "the Big Dance", protaganist => "al debaran", ref_east => [ "1.duke", "16.ndST", "8.vcu", "9.ucf", "5.msST", "12.lib", "4.vaTech", "13.stlouis", "6.maryland", "11.belmont", "3.lsu", "14.yale", "7.louisville", "10.mn", "2.miST", "15.bradley", ], region => "south", } -------system out--------- It is the Big Dance again, and I, al debaran, wanted to make some predictions. I pick to win in this round of the south. Their cardinality is . looks particularly likely to win, while the underdog. The current state of the Big Dance is . ---------------- out_file is /home/bob/Documents/meditations/hoops/my_data/22-03-2019-16-09-09/22-03-2019-16-09-09.2.txt pairs are 1.duke vs 16.ndST 8.vcu vs 9.ucf 5.msST vs 12.lib 4.vaTech vs 13.stlouis 6.maryland vs 11.belmont 3.lsu vs 14.yale 7.louisville vs 10.mn 2.miST vs 15.bradley pairs are 1.duke vs 16.ndST matched 1 duke 16 ndST { event => "hoops, baby", protaganist => "JAPH", ref_east => [ "1.duke", "16.ndST", "8.vcu", "9.ucf", "5.msST", "12.lib", "4.vaTech", "13.stlouis", "6.maryland", "11.belmont", "3.lsu", "14.yale", "7.louisville", "10.mn", "2.miST", "15.bradley", ], region => "south", } -------system out--------- It is hoops, baby again, and I, JAPH, wanted to make some predictions. I pick to win in this round of the south. Their cardinality is . looks particularly likely to win, while the underdog. The current state of hoops, baby is . ---------------- $ #### #!/usr/bin/perl -w use 5.011; use Path::Tiny; use utf8; use open OUT => ':utf8'; use Data::Dump; use Text::Template; use POSIX qw(strftime); binmode STDOUT, 'utf8'; my ($sub_dir) = $ARGV[0]; say "sub_dir is $sub_dir"; my $path1 = Path::Tiny->cwd; say "path1 is $path1"; my $path2 = path( $path1, $sub_dir ); say "path2 is $path2"; ## populate hash my $data = [ [ 'protaganist', 'al debaran', 'the narrator', 'JAPH', 'Dick Vitale' ], [ 'event', 'March Madness', 'the Big Dance', 'hoops, baby' ], [ 'region', 'east', 'west', 'south', 'midwest' ] ]; #dd $data; ## main loop # set trials my $trials = 2; my $dummy = 1; while ( $trials > 0 ) { # create an output file my $first_second = strftime( "%d-%m-%Y-%H-%M-%S", localtime ); my $out_file = $path2->child( 'my_data', "$first_second", "$first_second\.$dummy.txt" ) ->touchpath; say "out_file is $out_file"; # stochastic input of appositives my %vars = map { $_->[0], $_->[ rand( $#{$_} ) + 1 ] } @{$data}; my $rvars = \%vars; $rvars = pop_brackets($rvars); $rvars = calc_winners($rvars); dd $rvars; my @pfade = $path2->children(qr/\.txt$/); @pfade = sort @pfade; #say "paths are @pfade"; for my $file (@pfade) { #say "default is $file"; my $template = Text::Template->new( ENCODING => 'utf8', SOURCE => $file, ) or die "Couldn't construct template: $!"; my $result = $template->fill_in( HASH => $rvars ); $out_file->append_utf8($result); } say "-------system out---------"; system("cat $out_file"); say "----------------"; $trials -= 1; $dummy += 1; } # end while condition sub pop_brackets { my $rvars = shift; my %vars = %$rvars; my @east = qw(1.duke 16.ndST 8.vcu 9.ucf 5.msST 12.lib 4.vaTech 13.stlouis 6.maryland 11.belmont 3.lsu 14.yale 7.louisville 10.mn 2.miST 15.bradley); $vars{ref_east} = \@east; return \%vars; } sub calc_winners { use 5.016; use warnings; my $rvars = shift; my %vars = %$rvars; my $new_ref = $vars{ref_east}; my @east = @$new_ref; #say "east is @east"; my @pairs; while (@east) { my $first = shift @east; my $next = shift @east; push @pairs, "$first vs $next"; } say "pairs are @pairs"; my @winners = play_game(@pairs); return \%vars; # end calc_winners } sub play_game { use 5.016; use warnings; my @pairs = shift; say "pairs are @pairs"; my @winners; for my $line (@pairs) { if ( $line =~ /^(\d+)\.(\w+) vs (\d+)\.(\w+)$/ ) { say "matched"; say "$1 $2 $3 $4"; my $denominator = $1 + $3; my $ratio = $3 / $denominator; my $random_number = rand(); if ( $random_number < $ratio ) { push @winners, "$1.$2"; } else { push @winners, "$3.$4"; } } } return @winners; } # end play_game __END__