Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- # Example of a HashArray
- use Modern::Perl 2012;
- use Date::Calc qw(check_date);
- use autodie;
- use constant {
- ID => 0,
- DATE => 1,
- STORAGE => 2,
- ORDERD => 3,
- };
- my $ref = &generate_array;
- foreach my $key (sort {$a <=> $b} keys %{$ref}){
- my $calc =sprintf("%6s",${${$ref}{$key}}[STORAGE] + ${${$ref}{$key}}[ORDERD]);
- say "$key\t @{${$ref}{$key}} = $calc";
- }
- sub generate_array(){
- my %test;
- foreach (1 .. 10)
- {
- $test{$_}=[&generate_date, sprintf("%3.0f", $_), &number, &number];
- }
- return \%test
- }
- sub generate_date{
- my ($year,$month,$day);
- do {
- do {$year = sprintf("%4.0f", rand(2011));}until($year>1969);
- $month = sprintf("%02d", rand(12));
- $day = sprintf("%02d", rand(31));
- } until (check_date($year,$month,$day));
- return "$year-$month-$day";
- }
- sub number {
- return sprintf("%4.0f", rand(4999));
- }
Advertisement
Add Comment
Please, Sign In to add comment