I'm a beginner's level Perl user. I want to generate some test data for comparison of a couple of sorting algorithms. At first, I want to begin by generating a test set for N integer numbers. I should be able to read them from a file to which I wrote previously.
To generate test data, I do the following:My question is that whether this method is a good way to generate the test data and then apply the sort function or is there any wrong thing here? Thank you for your help.$array_size = <STDIN>; chomp ($array_size); #DEFINE NUMBER RANGE my $range = $array_size; open (DATASET, '>dataset.dat'); for ($count = 1; $count <= $array_size; $count++) { my $random_number = int(rand($range)); print DATASET $random_number; if($count != $array_size){ print DATASET "\n"; } } close (DATASET); #READ NUMBERS INTO AN ARRAY open (DATASET, '<dataset.dat'); my @numbers = <DATASET>; close (DATASET); my @sorted_numbers = sort { $a <=> $b } @numbers;
In reply to How to generate test data? by abdullah.yildiz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |