Hello all, I am kinda stuck with what I am trying to do. Here is my code.  I am creating a subroutine, which will be going into a larger script. Where I am stuck is trying to figure out the best to tackle to following problem.
#!/usr/bin/perl use strict; use Tie::File; use List::Util qw/shuffle/; my $line; my $i=0; my @array; my $count=0; my $alphaFile = 'alphabetFile.txt'; my $numberFile = 'numberFile.txt'; my $fileCounter = 'counter.txt'; my $tempFile = 'temp.txt'; open(FILECOUNTER,$fileCounter); $count = <FILECOUNTER>; chomp($count); &readfile(); sub readfile { tie @array, 'Tie::File', $numberFile || die("failed to open $numbe +rFile");; my %hashData; open(CHARFILE, $alphaFile) || die("failed to open $alphaFile"); if ($count == 5) { $count=0; unlink($tempFile); } else { $count++; } open(FILECOUNTER,">$fileCounter") || die("failed to open $fileCoun +ter"); print FILECOUNTER $count; close(FILECOUNTER); if (-e $tempFile) { open(TEMPFILE,"+<$tempFile") || die("failed to open $tempFile" +); while (<TEMPFILE>) { chomp; if ($_) { $_ =~ s/\s+//; $hashData{$_} = 1; } } } else { open(TEMPFILE,">>$tempFile") || die("failed to open $tempFile" +); } my $counter=0; tell(TEMPFILE); while ($line = <CHARFILE>) { chomp($line); if (exists $hashData{"$line$array[$i]"}) { next; } else { $hashData{"$line$array[$i]"} = 1; #print TEMPFILE "$line $array[$i]\n"; #print "$line $array[$i]\n"; if ("$line $array[$i]") { foreach ( $line ) { if ( $array[$i] ) { print $line . " "; print shuffle $array[$i] . "\n"; print TEMPFILE "$line $array[$i]\n" } else { print "\n" . $line . " " . rand "$array[$i]" . + "\n"; print TEMPFILE "$line $array[$i]\n" } } } } $i++; } print TEMPFILE "\n\n"; close(TEMPFILE); close(CHARFILE); untie @array; }
I am working with two sample files right now, just to get thing working.
alpha: has values 1-5, with 1 value per line
number: has values a-m, with 1 character per line.

Now what I need the code to do is the following:
print the data from $alphaFile with any of the numbers in $numberFile (random is fine, order does not really matter).

Once it prints to STDOUT, it should also keep track of what was printed. Which is where the tempFile comes in.  

Now the next time the script runs, it should check the tempFile before it print outs the data to STDOUT. It should check to make sure that the combinations that it is now printing, have not occurred during the last run.  It does this by checking the data stored in the tempFile.  It will keep track of the last five times the script has been run, along with what was printed. And during those five times the script should not print any of the same combinations.
for example: RUN1 output a 1 b 2 c 3 skipping… l 3 m 1 RUN2 output a 3 b 5 c 1 skipping… l 2 m 4 RUN3 output a 5 b 1 c 4 skipping… l 1 m 5
Each time the script runs it should not print the same combination of data. So it should, again, check the tempFile, where it stores each run and shuffle/rand the data until is unique (This is where I am having problems/Stuck).

I am having two main problems, which I am beating my head trying to figure. How to I get it to print a random number once all the numbers in the hash have been used? Right now it prints fine the first time, but once it gets to all the numbers in the hash it does not print a number, nor does it print any of the alphas. It currently only print 5 values after the first run, but prints all of them during the first run. I added a few new lines but they are decimal numbers not random numbers from the hash($numberFile)

Any help pointers would be greatly appreciated.  I think i've been playing with this for so long that i need a second pair of eyes.  
Thanks for all the help.

In reply to Hash shuffle help by perlnewbie9292

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.