小骆驼 第三章 列表与数组

南笙酒味 提交于 2020-03-07 21:28:36

环境上下文

#!/usr/bin/envperl

use strict;
use warnings;


$_ = "ABCDEFG";print;print"\n";

##ABCDEFG

$_ = reverse $_;print;print "\n";

##GFEDCBA

my @arr = reverse (1..10); print "@arr\n";

##10 9 8 7 6 5 4 3 2 1

my @number = sort (1..10);print "@number\n";

##1 10 2 3 4 5 6 7 8 9

my @fruit = qw{ apple banana peach };
while (my ($name,$choice) = each @fruit  ) 
{
  print "$name****$choice\n";
}

##0****apple
##1****banana
##2****peach

my @new_fruit = sort @fruit;print "@new_fruit\n";
my $new_fruit = 42 + @new_fruit;print "$new_fruit\n";

##apple banana peach
##45

my $wrong_example = sort @fruit;print "$wrong_example\n";

##Use of uninitialized value $wrong_example in concatenation (.) or string at test.pl line 39.

my @new_fruit1 = reverse @fruit;print "@new_fruit1\n";
my $new_fruit1 = reverse @fruit;print "$new_fruit1\n";

##peach banana apple
##hcaepananabelppa

my $dino;($dino) = @fruit;

foreach(($dino))
{
  print;print "\n";
}

##apple

while(@fruit)
{
  pop @fruit;print"@fruit\n";
}

##apple banana
##apple
##

my @a = 9*8;print "@a\n";

my @b = "a"."c";print "@b\n";

##72
##ac

@a = undef;print "@a\n";

@b = ();print "@b\n";

##Use of uninitialized value $a[0] in join or string at test.pl line 74.
##

问题一:
此处的数组应该如何排序?

my @number = sort (1..10);print "@number\n";

##1 10 2 3 4 5 6 7 8 9
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!