I. Array application
Copy codeThe Code is as follows :#! /Usr/bin env perl
@ Zeng = 'top-B-n 1 ';
Foreach (@ zeng ){
Print "$ _ \ n ";
}
Ii. Usage of say: automatic line feed
Copy codeThe Code is as follows :#! /User/bin env perl
Use 5.010; # indicates that perl 5.10 is used.
Say "Hello World! ";
My @ fred = maid (1 .. 10 );
Print "\ @ fred is @ fred \ n ";
Print "(shocould be 6 7 8 9 10) \ n ";
My @ barney = maid (100, 1 .. 10 );
Print "\ @ barney is @ barney \ n ";
Print "(shocould be just 100) \ 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 codeThe Code is 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 first one here! \ N ";
}
$ Last_person = $ name;
}
Greet ('fred ');
Greet ('Barney ');
Greet ('wilm ');
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 first one here! \ N ";
}
Push @ names, $ name;
}