tailieunhanh - Web Server Programming phần 3

Sắp xếp mặc định hành vi của các phân loại chữ cái có thể được sửa đổi, bạn có để cung cấp trợ giúp chương trình con sắp xếp của bạn. Các chức năng trợ giúp để có thể phân loại là một chút không điển hình của người sử dụng xác định thói quen, nhưng họ không khó để viết. | 112 Perl Sorted Sorted alphabetically Sorted -11 100 26 3 3001 49 78 The default sort behavior of alphabetic sorting can be modified you have to provide your own sort helper subroutine. The helper functions for sorting are a little atypical of user-defined routines but they are not hard to write. Your routine will be called to return the result of a comparison operation on two elements from the array - these elements will have been placed in the global variables a and b prior to the call to your subroutine. This use of specific global variables is what makes these sort subroutines different from other programmer-defined routines. The following code illustrates the definition and use of a sort helper subroutine numeric_sort . share bin perl -w sub numeric_sort if a b return -1 elsif a b return 0 else return 1 @list2 100 26 3 49 -11 3001 78 @slist2 sort @list2 print List2 @list2 n print Sorted List2 default sort @slist2 n @nlist2 sort numeric_sort @list2 print Sorted List2 numeric sort @nlist2 n Perl has a special operator for numeric comparisons using this operator the numeric sort function could be simplified sub numeric_sort @a b Perl permits in-line definition of sort helper functions allowing constructs such as @nlist2 sort a b @list2 Two simple list examples Many simple databases and spreadsheets have options that let you get a listing of their contents as a text file. Such a file will contain one line for each record fields in the record will be separated in the file by some delimiter character usually the tab or colon character . For example a database that recorded the names roles departments rooms and phone numbers of employees might be dumped to file in a format like the following Beyond CS1 lists and arrays 113 Painter Buildings Grounds 3456 Audit clerk Administration 3383 Help line Sales 4222 Perl programs can be very effective for processing such data. The input lines can be broken into lists of elements. The

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.