xxsr.net
当前位置:首页 >> pErl print 数组 >>

pErl print 数组

方法: my @array = (0, 1, 2, 3); print (“@array\n”); #输出有空格,如:0 1 2 3 print (@array, “\n”); #输出没空格,如:0123 哈希也可以用同样方法,如: my %hash = (); $hash{a} = ‘jeftom'; $hash{b} = ‘design'; print (%hash);

#上面的写法可以@array=(1..50);print @array[30..50];#或者也可以这样:@array=(1..50);for $i (30..50) {print $array[$i];}

print join ',',@your_array;

#! /usr/bin/perl use strict; use warnings; my @array = (0 .. 9); my $tmp = 10; print "@array\n"; push(@array,$tmp); print "@array\n"; @array = $tmp + 1; print "@array\n"; ------------------------------------------------- 输出:...

你可以用hash,将名字作为键,指向一个数组,例如: perl -le ' $hash{"test"}[0]=1 ; $hash{"test"}[1]=100 ; print "@{$hash{\"test\"}}" ; '

@a = ('P','e','r','l'); $s = join('',@a); print $s;

$path='C:\Users\' ; #路径opendir D1, "$path" or die $!; @array=grep(!/\.\.?$/, readdir D1); print @array;

@nums = ( 1..10 );$sum += $_ foreach @nums;$avg = $sum/scalar(@nums); # scalar() 是用来找出数组中有几个元素的指令print "average of \"@nums\" is $avg";

perl -e ' @array=(1,2,3) ; $r = \@array ; @a2 = @$r ; print "@a2" ; '\@array 就是取得数组的一个引用,类似于指针,@$r可以解引用

sub choose(){ my (@c1, @c2, @c3); @c1 = @_; @c2 = sort @_; @c3 = reverse @_; return (\@c1,\@c2,\@c3); } my @arr = (1,2,3,5,4); my (@a,@b,@c); my @refs = &choose(@arr); @a = @{$refs[0]}; @b = @{$refs[1]}; @c = @{$refs[2]}; print...

网站首页 | 网站地图
All rights reserved Powered by www.xxsr.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com