Perl语言入门笔记 第十五章 智能匹配与given-when结构

前端之家收集整理的这篇文章主要介绍了Perl语言入门笔记 第十五章 智能匹配与given-when结构前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
=pod
第十五章	智能匹配与given-when结构

智能匹配操作符:~~
	use 5.010001;
	say "I found Fred in the same" if $name ~~ /Fred/;
	找出哈希表中是否包含“Fred”
	use 5.010001;
	say "I found a key matching 'Fred'" if %name ~~ /Fred/;
	use 5.010001;
	my @nums = qw(1 2 3 27 42);
	my $result = max(@nums);
	
	say "The result [$result] is one of the input values()@nums" if $result ~~@nums;
	
given语句:像c语言中的switch语句
	given($ARGV[0])
	{
		when ($_ ~~ 'Fred') {  }
		when ($_ ~~ /Fred/i) {  }
		when ($_ ~~ /\Afred/)
		default {	}	
	}

笨拙匹配:
	~~加正则表达式
	
多个条目的when结构:
	来个循环,说出你的原因

=cut

猜你在找的Perl相关文章