Created
August 20, 2014 06:00
-
-
Save Code-Hex/e71cf1967cbf09d470c1 to your computer and use it in GitHub Desktop.
Perl の sort関数、reverse関数を使用しての例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/perl | |
use strict; | |
use warnings; | |
my $n = "\n"; | |
my @array = qw/3 8 5 4 2 9 5 0 1 7 6 11 23 38 99 100/; | |
print "First!!\n"; | |
print "$_ " foreach (@array); | |
print $n x 2; | |
my @sorted = sort @array; # 先頭の位を比べてソート | |
print "Num Sorted\n"; | |
print "$_ " foreach (@sorted); | |
print $n x 2; | |
@sorted = reverse sort @array; | |
print "Num reverse Sorted\n"; | |
print "$_ " foreach (@sorted); | |
print $n x 2; | |
my @array2 = qw/a d e b c f apple banana melon/; | |
@sorted = sort @array2; # 先頭の文字を比べてソート | |
print "Char Sorted\n"; | |
print "$_ " foreach (@sorted); | |
print $n x 2; | |
@sorted = reverse sort @array2; | |
print "Char reverse Sorted\n"; | |
print "$_ " foreach (@sorted); | |
print $n x 2; | |
= result | |
First!! | |
3 8 5 4 2 9 5 0 1 7 6 11 23 38 99 100 | |
Num Sorted | |
0 1 100 11 2 23 3 38 4 5 5 6 7 8 9 99 | |
Num reverse Sorted | |
99 9 8 7 6 5 5 4 38 3 23 2 11 100 1 0 | |
Char Sorted | |
a apple b banana c d e f melon | |
Char reverse Sorted | |
melon f e d c banana b apple a | |
=cut |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
そーっとね!(笑)