xxsr.net
当前位置:首页 >> pErl子程序返回多个数组到主程序中多个数组 >>

pErl子程序返回多个数组到主程序中多个数组

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

示例: #!/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...

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

my $str='dsfsfsf"DEV1234"dfsfsdfs"DEV232323" sfdasjklas“DEV32323”'; my @collector; my $cp = $str; $cp =~ s/(DEV\d+)/push @collector, $1/eg; print "@collector";

可以试一下这几种方式,每种方式各有优劣: #!/bin/perl -w use strict; my @arr = ( "aaa","bbb","ccc","ddd","eee","fff"); # 这个是数组 my $vv = "ddd"; # 这个是要查找的变量 # 方法1,:使用类似c语言的风格,遍历这个数组,查找变量是否匹...

两种方法,1:要是ab按照顺序排的话my ($i, $j) = (0, 0);AA: while ($i $#b);}if ($b[$j] == $a[$i]){print "delete $a[$i]\n";splice(@a, $i, 1);}else{$i++;}}print "@a";2:要是不按照顺序可以用hashfor (@b){$b{$_} = 1;}$i = 0;while ($i

这种应该没有什么好的办法,数据量不大的话,编写一个函数isInArray($val, @array),来判断一个数值是否在数组里,存在就返回1,不存在就返回0。 然后遍历另一个数组,分别判断是否在另一个数组里存在。 数据量大的话也可以这样做,不过事先对两...

@data = qw/ 1 2 3 /; push @data, 5; #---数组后加5,@new = push @data, 5整个语句返回加过5后的元素个数即为4 print "@data\n"

如果有 3 个或以上呢 ? sub getMax { my (%temp, $max, @ret); foreach ( @_ ) { my $count = $temp{$_}++; $max = $count if $count > $max; } foreach ( keys %temp ) { push @ret, $_ if $temp{$_} == $max } return @ret;}print getMax ( sp...

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

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