tailieunhanh - Minimal Perl For UNIX and Linux People 10

$ CL_VERBOSE=2 check_links Got 101 links for 85 links are unique Checking '': OKAY Checking '': OKAY . BAD: '', in '' $ CL_VERBOSE=3 check_links # Output edited to fit Got 101 links for 85 links are unique Checking '': OKAY Type: text/html Size: N/A Server: Apache/ . Checking '': OKAY Type: text/html Size: N/A Server: Apache/ . . BAD: '', in '' Verbosity level 3 dumps out the data obtained by the head function from the web server, if any; otherwise it reports the link being tested as “BAD”. Now look at the script, which is. | CL_VERBOSE 2 check_links Got 101 links for 85 links are unique Checking http D A OKAY Checking http M A OKAY . BAD https in CL_VERBOSE 3 check_links Output edited to fit Got 101 links for 85 links are unique Checking http D A OKAY Type text html Size N A Server Apache . Checking http M A OKAY Type text html Size N A Server Apache . . BAD https in Verbosity level 3 dumps out the data obtained by the head function from the web server if any otherwise it reports the link being tested as BAD . Now look at the script which is presented in listing . It begins by importing LWP Simple which exports the head function automatically. It then checks for the variable CL_VERBOSE in the environment if it has a number in it that number is copied to the file-scoped variable VERBOSE so the requested verbosity level can conveniently be determined from anywhere within the program. On Line 25 the lwp-request command obtains the list of links found within the current page and then if tests the True False value of the array @links to determine whether links were found. Many pages contain multiple links to other pages so Line 32 filters the duplicates out of @links we ll come back to this . Listing The check_links script 1 usr local bin perl -wl 2 3 use strict 4 use LWP Simple 5 6 my VERBOSE 0 file scope 7 defined ENV CL_VERBOSE and ENV CL_VERBOSE A d and 8 VERBOSE ENV CL_VERBOSE if numeric value assign 9 10 MAIN program 11 foreach my url @ARGV check_link url 12 13 14 END 15 If propeller was last thing written to screen 16 will need n before shell s upcoming prompt to STDERR 17 print STDERR 18 406 CHAPTER 12 Modules and the CPAN 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 sub check_link my

TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
165    131    2    22-11-2024
28    152    1    22-11-2024
6    132    0    22-11-2024
6    117    1    22-11-2024
22    147    2    22-11-2024
89    125    0    22-11-2024
7    104    0    22-11-2024
54    143    1    22-11-2024
3    106    0    22-11-2024
5    99    0    22-11-2024