tailieunhanh - Minimal Perl For UNIX and Linux People 9

Từ một quan điểm Perlish, bạn có thể lựa chọn như là một loại đặc biệt của biến thể tương tác trên một vòng lặp foreach. Nhưng thay vì có mỗi danh sách giá trị được giao tự động để biến vòng lặp cho một lặp đi lặp lại, chọn chỉ gán giá trị khi họ được lựa chọn bởi người sử dụng. Tiếp theo, bạn sẽ thấy làm thế nào bạn có thể tránh những "phát minh lại bánh xe" bằng cách sử dụng vòng lặp này | From a Perlish perspective you can think of select as a special kind of interactive variation on a foreach loop. But rather than having each list-value assigned automatically to the loop variable for one iteration select only assigns values as they are selected by the user. Next you ll see how you can avoid re-inventing wheels by using this loop. Avoiding the re-invention of the choose-from-a-menu wheel Although Perl has no counterpart to the Shell s handy select loop its functionality is provided by a CPAN module called Shell POSIX It provides its services through source-code filtering which means it extracts the select loops from your program and rewrites them using native Perl features. As a result you can use a feature that s missing from Perl as if it were there The benefit of bringing the select loop to Perl is that it obviates the need for terminal applications to provide their own implementations of the choosefrom-a-menu code which indulges the programmer s noble craving for Laziness and thereby increases productivity. Table shows the syntax variations for the Shell s version of the select loop. Table The Shell s select loop select var do commands done Form 0 select var in LIST do commands done Form 1 If in LIST is omitted as in Form 0 in @ is used by default to provide automatic processing of the script s or function s argument list. Some of the major forms of Perl s select loop are shown in table . These take their inspiration from the Shell and then add enhancements for greater friendliness and well Perlishness. Table The select loop for Perl use Shell POSIX Select select Form 0 select CODE Form 1 select LIST CODE Form 2 select var LIST CODE Form 3 As you can see Perl s select lets you omit any or even all of its components apart from the punctuation symbols . For example if the loop variable is omitted as in Forms 0 1 and 2 _ is used by default. If the LIST is omitted as in Forms 0 and 1 the appropriate arguments .

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.