MCslp HomeMCslp Home Contact | About | Help | Legal
Books | Articles | Downloads
News | News Archive
 
 
 
The first chapter covers the use of Perl as a language for analyzing and processing text. Script examples include a file encryption/decryption utility, a script for decoding uuencoded files, and a very simple web log analyzer.
Download: PC - Unix - Mac - Info
Chapter Script Status

TitleScript NameStatus
Converting the Text Format of Multiple Files dos2ux.pl No Change
Faster File Conversions None No Change
Uudecoding Files uudecode.pl No Change
File Encryption encrypt.pl
decrypt.pl
No Change
Processing a Standard Web Log weblog.pl Bug Fix, 13th Nov 1999

Web Log Processor Update

Under certain circumstances, the regular expression used to identify the individual fields in the log can fail to pick up the information. The problem is actually very simple - some web servers produce logs with a trailing space.

The current script has the following line:

$matched = /^(\S+)\s+(\S+)\s+(\S+)\s+\[(.*)\]
            \s+"(.*)"\s+(\S+)\s+(\S+)$/x;

the problem is that the trailing '$' character indicates to only match the last field if it is right at the end of the line. The solution is to add a simple expression to match zero, or more, space characters at the end of the line:
$matched = /^(\S+)\s+(\S+)\s+(\S+)\s+\[(.*)\]
            \s+"(.*)"\s+(\S+)\s+(\S+)[ ]*$/x;

Download the updated script: PC - Unix - Mac

 PAA Quick Links
 

Book Summary
Book Outline
Chapter Contents
Chapter and Script Details
Download Chapter 4 Free! (PDF, 540k)

 Buy Perl: The Complete Reference
 

Perl the Complete Reference has been superceded by Perl The Complete Reference 2ed...


Website (c) 1998 and beyond Martin C Brown, MCSLP, UK. All other items, including contributed texts, files and information is the copyright of their respective owners.
Contact Us