如何找出此字符串中的磁盘数?
$str='disk 0_1 0_2 0_3';
在此$str
中,磁盘数为3。
Perl如何输出此字符串中有多少个磁盘?
谢谢!
答案 0 :(得分:3)
my $count = () = $str =~ /\d+_\d+/g;
答案 1 :(得分:1)
尝试:
$disk_count = scalar( split ' ', $str) - 1;
答案 2 :(得分:1)
my @result = $str=~ m/\d_\d/g;
print "Number of disks found : ", scalar(@result), "\n";
答案 3 :(得分:0)
my $counter = 0;
$counter++ while ($str =~ m/\d+_\d+/g);