#!/usr/bin/perl use strict; use YAML qw(); my $kGenLines = 3; my $history = eval {YAML::LoadFile('history.yaml')} || {}; # Adjust history $history->{$_} && --$history->{$_} for keys %$history; #generate lines my @alphas = 'A' .. 'M'; my @nums = 1 .. 5; LINES: for (1 .. $kGenLines) { my @aPool = @alphas; my $pair; while (@aPool) { my @nPool = @nums; my $tryAlpha = splice @aPool, rand(@aPool), 1; while (@nPool) { my $tryNum = splice @nPool, rand(@nPool), 1; next if $history->{"$tryAlpha|$tryNum"}; @alphas = grep {$_ ne $tryAlpha} @alphas; @nPool = grep {$_ != $tryNum} @nPool; print "$tryAlpha $tryNum\n"; $history->{"$tryAlpha|$tryNum"} = 5; next LINES; } @alphas = grep {$_ ne $tryAlpha} @alphas; } } YAML::DumpFile('history.yaml', $history);