Created
August 20, 2014 04:45
-
-
Save Code-Hex/b578667c7e7af5c82c5d to your computer and use it in GitHub Desktop.
push,popとshift,unshiftについて
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 @array = qw/1 2 3 4 5 6 7 8/; | |
print "first!!\n"; | |
print "$_ " for (@array); | |
print "\n"x2; | |
my $a = pop @array; # 配列の一番最後の配列を抜き出す | |
print "pop!!\n"; | |
print "$_ " for (@array); | |
print "\n"x2; | |
push @array, $a; | |
print "push!!\n"; | |
print "$_ " for (@array); | |
print "\n"x2; | |
print "pop,pushと同じようにshift,unshiftも使えるけど少し違う!\n\n"; | |
print "first!!\n"; | |
print "$_ " for (@array); | |
print "\n"x2; | |
my $b = shift @array; # 配列の先頭の配列を抜き出す | |
print "shift!!\n"; | |
print "$_ " for (@array); | |
print "\n"x2; | |
unshift @array, $b; | |
print "unshift!!\n"; | |
print "$_ " for (@array); | |
print "\n"; | |
= 実行結果 | |
first!! | |
1 2 3 4 5 6 7 8 | |
pop!! | |
1 2 3 4 5 6 7 | |
push!! | |
1 2 3 4 5 6 7 8 | |
pop,pushと同じようにshift,unshiftも使える! | |
first!! | |
1 2 3 4 5 6 7 8 | |
shift!! | |
2 3 4 5 6 7 8 | |
unshift!! | |
1 2 3 4 5 6 7 8 | |
=cut |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
初めての人は困惑するよね...