学习perl点滴(二)

前端之家收集整理的这篇文章主要介绍了学习perl点滴(二)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

shift用法

#!/usr/bin/perl
sub check_required_items {
    my $who = shift;
    print "$who\n";
    my %who_items = map {$_,1} @_;
    my @required = qw(preserver sunserver water_bottle jacket);
    for my $item (@required) {
        unless ($who_items{$item}) {
                 print "$who is missing $item.\n";
        }
    }
}
my @gilligan = qw(red_shirt hat luc water_bottle);
check_required_items('gilligan',@gilligan);


输入结果:

gilligan

gilligan is missing preserver.

gilligan is missing sunserver.

gilligan is missing jacket.

shift 取数组中第一个变量,并在列表中剔除变量,有点像pop;

猜你在找的Perl相关文章