#!/usr/bin/perl
use 5.010;
given ($ARGV[0]) {
when( /tom/i ) {say 'Name has tom in it'}
when( /^tom/ ) {say 'Name starts with tom'}
when( 'tom' ) {say 'Name is tom'}
default {say "I don't see tom"}
}
$ ./given.pl
I don't see tom
$ ./given.pl tomdkjaekda
Name has tom in it
#!/usr/bin/perl
use 5.010;
given ($ARGV[0]) {
when( /tom/i ) {say 'Name has tom in it';continue}
when( /^tom/ ) {say 'Name starts with tom'}
when( 'tom' ) {say 'Name is tom'}
default {say "I don't see tom"}
}
]$ ./given.pl tomdkjaekda
Name has tom in it
Name starts with tom
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |