Author: Not specified Language: perl
Description: Not specified Timestamp: 2017-09-23 16:47:24 +0000
View raw paste Reply
  1. use strict;
  2. use warnings;
  3.  
  4. my @numbers = (9, 3, 5, 6, 2);
  5. my $s = "c";
  6.  
  7. print "@numbers\n";
  8.  
  9. Sorting($s,\@numbers);
  10.  
  11. exit(0);
  12.  
  13. sub Sorting{
  14.     my $s2 = $_[0];
  15.     my @n2 = @{$_[1]};
  16.    
  17.     if($s2 eq "c"){
  18.         @n2 = sort { $a <=> $b } @n2;
  19.     }
  20.     if($s2 eq "d"){
  21.         @n2 = sort { $b <=> $a } @n2;
  22.     }
  23.  
  24.     print "@n2\n";
  25. }
View raw paste Reply