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

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

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

试验的: C:\Users\Administrator>perl -e "@a=(1,2); $b=[@a]; @c=@$b ; print \"@a : $b : @c \" " 1 2 : ARRAY(0xa031c20) : 1 2 建议将 my @prime_r = @neme_hasg{$str}; 修改为 my @prime_r = @$neme_hasg{$str}; 试试

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

自己写个吧也简单 print max(9,5,10,1); sub max{ my $mx = $_[0]; for my $e(@_) {$mx = $e if ($e > $mx);} return $mx; }

示例: #!/usr/bin/perl -w use strict; my @array1 = (["a","b","c"],["d","e","f"],["g","h","i"]); my @array2 = (["a","b","c"],["d","e","f"]); &test (\@array1, \@array2); &test (\@array1, \@array2); sub test { my ($subarray1, $sub...

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

while(){ chomp; unless(/^M/){ @tmp=split; $count{$tmp[0]}++;##统计第一列数字个数 } } print "$count{1}\n";##1的个数 你的代码没贴完 不知道到底是哪里。。

首先来个基本函数参数的传递 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