Two snippets of Perl scripting code (array application and say usage) _perl

Source: Internet
Author: User
One, array application
Copy Code code as follows:

#!/usr/bin Env Perl
@zeng = ' top-b-n 1 ';
foreach (@zeng) {
print "$_\n";
}

second, the use of say: Automatic line wrapping
Copy Code code as follows:

#!/user/bin Env Perl
Use 5.010; The version of #表示使用perl 5.10.
Say "Hello world!";
My @fred = Above_average (1..10);
Print "\ @fred is @fred \ n";
Print "(Should be 6 7 8 9) \ n";
My @barney = above_average (100, 1..10);
Print "\ @barney is @barney \ n";
Print "(Should be just) \ n";
Sub Average {
if (@_ = = 0) {return}
my $count = @_;
My $sum = Total (@_);
$sum/$count;
}

Sub Above_average {
My $average = average (@_);
My @list;
foreach my $element (@_); {
if ($element > $average) {
Push @list, $element;
}
}
@list;
}

Copy Code code as follows:

#!/usr/bin/perl-w
Use 5.010;
Greet (' Fred ');
Greet (' Barney ');
Sub Greet {
State $last _person;
my $name = shift;
Print "Hi $name!";
if (defined $last _person) {
Print "$last _person is also here!\n";
}
else {
Print "You are the one here!\n";
}
$last _person = $name;
}
Greet (' Fred ');
Greet (' Barney ');
Greet (' Wilma ');
Greet (' Betty ');
Sub Greet {
State @names;
my $name = shift;
Print "Hi $name!";
if (@names) {
Print "I ' ve seen: @names \ n";
}
else {
Print "You are the one here!\n";
}
Push @names, $name;
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.