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];}

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

@m=([[1,2,3],[2,3,4]],[[1,5],[2,6]]); for $i(0..$#m) { for $j(0..$#{$m[$i]}) { for $k(0..$#{$m[$i][$j]}) { print $m[$i][$j][$k]," "; } } }

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

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

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

use Array::Compare; my @arr1 = 0 .. 10; my @arr2 = 0 .. 10; my $comp1 = Array::Compare->;new; if ($comp1->;compare(\@arr1, \@arr2)) { print "Arrays are the same\n"; } else { print "Arrays are different\n"; }

%kwhash; open(LIST,"List.txt"); while(){ chomp; $kwhash{$_} = 1 ; } close LIST; open(KW, "kwList.txt"); while(){ chomp; my ($name) = split/\,/,$_; #print $name; next if (exists $kwhash{$name}); print $name; print "\n"; } close ...

首先来个基本函数参数的传递 sub hello { print "Hello @_" }hello ("World!", "I am Robot" ) ; # 打印出 Hello World! I am Robot这里值得留意的就是 @_ 就是装载所有传入的参数的数组 ( 看好了, 这其实是数组啊!! ) 所以, 将上面的改一下, 就...

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