abdullah.yildiz has asked for the wisdom of the Perl Monks concerning the following question:
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to generate test data?
by roboticus (Chancellor) on Nov 24, 2012 at 17:21 UTC | |
by abdullah.yildiz (Novice) on Nov 24, 2012 at 17:31 UTC | |
|
Re: How to generate test data?
by karlgoethebier (Abbot) on Nov 24, 2012 at 18:22 UTC | |
by abdullah.yildiz (Novice) on Nov 25, 2012 at 00:48 UTC | |
by roboticus (Chancellor) on Nov 25, 2012 at 02:33 UTC | |
by abdullah.yildiz (Novice) on Nov 25, 2012 at 11:48 UTC |