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);

print join ',',@your_array;

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

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

你是指输出除数组第一个元素以外的其他元素吧?print " $array[1..-1] ";

#! /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"; ------------------------------------------------- 输出:...

$" = "\n"; @arr = (1, 2, 3, 4, 5); open OUT, "> a.txt"; print OUT "@arr"; 数组内插时,分隔符默认$"的值,可以通过修改$"的值来修改如何分割

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

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...

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

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