Great many thanks for your input, I have started rewriting my code before even reading all your post, so here is my take on your advice:
#!/usr/bin/perl
#this is a perl implementation of the radoteur from the book "Théorie
+du Bordel
#Ambiant" authored by the french researcher Roland Moreno
#It will take a word list as input and output giberrish-y words from i
+t, after
#a while it will cycle, this program has been specially written to ide
+ntify
#the relationship between the wordlist and the size of the cycles
#next thing would be to do some stat works on the word size, their num
+bers
#inside the wordlist to find the equation that models the word list -
+cycle
#size the most accurately
use strict;
use warnings;
use autodie;
my($evt,$niter);
my $cycled = 0;
$niter= 0;
#this is a double hash, the first level keys are line numbers, the sec
+ond
#its values are another hash which keys are letter coordinates inside
+the
#line's word, if we have the same letter in the same word on the same
+line
#appear twice then we have cycled
my %letter_lines;
if(!defined $ARGV[0]){
die "to use me, give me the word list file as argument\n";
}
while($cycled == 0){
open my $fh, '<',$ARGV[0];
FILE_ITER: while(<$fh>){
#here I take in the new word and split it into its letters
#I also count the iteration number
my $word = $_;
$niter++;
my @letters = split("", $word);
#if evt is undefined, that's because we were looking for a
+ newline
#in the previous event or its the first iteration, in any
+case
#the new event will be the first letter of the current wor
+d
if(!defined($evt)){
if(defined $letter_lines{$.}{0}){
warn "we have cycled: doing line $. letter
+ 0
again\n";
$cycled = 1;
last FILE_ITER;
}
else{
$letter_lines{$.}{0} = 1;
warn "adding to hash line $. letter 0\n";
}
$evt = shift @letters;
print $evt;
next FILE_ITER;
}
else{
WORD_ITER:foreach my $i (0 .. $#letters){
if($evt eq $letters[$i]){
my $j = $i+1;
$evt = $i < $#letters?$letters[$j]:undef;
if(defined $evt){
if(defined $letter_lines{$.}{$j}){
warn "we have cycled :
line $. letter $j \n";
$cycled = 1;
last FILE_ITER;
}
else{
warn "adding to hash line $.
letter $j\n";
$letter_lines{$.}{$j} = 1;
print $evt;
}
}
last WORD_ITER;
}
}
}
}
close($fh);
warn "going back to the beginning\n";
}
warn "cycled in $niter iterations\n";