小骆驼 第三章 列表与数组

本文深入探讨了Perl中数组的使用与排序方法,包括直接排序、反转排序、元素遍历及组合应用,展示了如何利用Perl语言的强大功能进行高效的数据处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境上下文

#!/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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值