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

原文地址:https://www.cnblogs.com/v-BigdoG-v/p/7398609.html