YUANya

导航

 

环境上下文

#!/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
posted on 2019-06-12 00:53  YUANya  阅读(95)  评论(0编辑  收藏  举报