Posted on Netease blog 21:22:33
3.1 list Printing
# When reading each list value from stdin, it is processed by chomp. Therefore, each list element is removed from the line break at the end.
Chomp (@ lines = <stdin> );
Print "print the list \ n ";
Foreach $ line (@ lines ){
Print "$ line \ t ";
}
Print "\ n ";
Print "print the list reverse \ n ";
@ Lines_reverse = reverse (@ lines );
Foreach $ list (@ lines_reverse ){
Print "$ list \ t ";
}
3.2 print the existing list by index
# Print array2
@ Namelist = QW (Fred Barney Betty Wilma Dino );
Chomp (@ indexlist = <stdin> );
Print "@ namelist ";
Foreach $ index (@ indexlist ){
Print "the $ index element in list is: \ t $ namelist [$ Index] \ n ";
}
3.3 The list content is output in the same row and in different rows
Chomp (@ namelist = <stdin> );
@ Sortednamelist = sort (@ namelist );
Print "print in one line: \ t @ {sortednamelist} \ n ";
Print "Print elements in list in different lines; \ n ";
Foreach $ element (@ sortednamelist ){
Print "$ element \ n ";
}