Minimal Perl: For UNIX and Linux People
暫譯: 最小化 Perl:針對 UNIX 和 Linux 使用者

Tim Maher

  • 出版商: Manning
  • 出版日期: 2006-10-01
  • 售價: $1,488
  • 貴賓價: 9.5$1,414
  • 語言: 英文
  • 頁數: 464
  • 裝訂: Paperback
  • ISBN: 1932394508
  • ISBN-13: 9781932394504
  • 相關分類: LinuxPerl 程式語言
  • 立即出貨 (庫存=1)

買這商品的人也買了...

相關主題

商品描述

Description

"If you are a Unix/Linux user and wish to learn Perl, I recommend this book."
-- George Wooley,
Camelot.pm and Oakland.pm

"This book is not perl tapas. It is a survival tool."
-- William M. Julien, HPC Unix Performance Analyst, Fortune 100 Company

"No-nonsense and practical, yet with wit and charm. A joy to read."
-- Dan Sanderson, Software Developer

"Shows style, not just facts, valuable."
-- Brian Downs, former Training Director, Lucent Technologies

"Brilliant, never tedious, highly recommended!"
-- Jon Allen, Maintainer of perldoc.perl.org

"You could have chosen no better primer than this book."
-- Damian Conway, from the Foreword

Perl is a complex language that can be difficult to master. Perl advocates boast that "There's More Than One Way To Do It", but do you really want to learn several ways of saying the same thing to a computer?

To make Perl more accessible, Dr. Tim Maher has over the years designed and taught an essential subset of the language that is smaller, yet practical and powerful. With this engaging book you can now benefit from "Minimal Perl", even if all you know about Unix is grep.

You will learn how to write simple Perl commands (many just one-liners) that go far beyond the limitations of Unix utilities, and those of Linux, MacOS/X, etc. And you雍l acquire the more advanced Perl skills used in scripts by capitalizing on your knowledge of related Shell resources. Sprinkled throughout are many Unix-specific Perl tips.

This book is especially suitable for system administrators, webmasters, and software developers.

 

Table of Contents

foreword
preface
acknowledgments
about this book
about the cover illustration
list of tables

Minimal Perl: for UNIX and Linux Users

1 Introducing Minimal Perl
A visit to Perlistan
Sometimes you need a professional guide
Perl can be simple
About Minimal Perl
What Minimal Perl isn't, What Minimal Perl is
Laziness is a virtue
A minimal dose of syntax
Terminating statements with semicolons
Writing one-line programs
Balancing simplicity and readability, Implementing simple filters
Summary
2 Perl essentials
Perl's invocation options
One-line programming: -e, Enabling warnings: -w, Processing input: -n, Processing input with automatic printing: -p, Processing line-endings: -l, Printing without newlines: printf, Changing the input record separator: -0digits
Using variables
Using special variables, Using the data variable: $_, Using the record-number variable: $., Employing user-defined variables
Loading modules -M
Writing simple scripts
Quoting techniques, True and False values, Handling switches: -s, Using warn and die, Using logical and, logical or, Programming with BEGINand END blocks, Loading modules with use
Additional special variables
Employing I/O variables, Exploiting formatting variables
Standard option clusters
Using aliases for common types of Perl commands
Constructing programs
Constructing an output-only one-liner, Constructing an input/output script
Summary
Directions for further study
3 Perl as a (better) grep command
A brief history of grep
Shortcomings of grep
Uncertain support for metacharacters, Lack of string escapes for control characters, Comparing capabilities of greppers and Perl
Working with the matching operator
The one-line Perl grepper
Understanding Perl's regex notation
Perl as a better fgrep
Displaying the match only, using $&
Displaying unmatched records (like grep -v), Validating data, Minimizing typing with shortcut metacharacters
Displaying filenames only (like grep -l)
Using matching modifiers
Ignoring case (like grep -i)
Perl as a better egrep
Working with cascading filters
Matching in context
Paragraph mode, File mode
Spanning lines with regexes
Matching across lines, Using lwp-request, Filtering lwp-request output
Additional examples
Log-file analysis, A scripted grepper, Fuzzy matching, Web scraping
Summary
Directions for further study
4 Perl as a (better) sed command
A brief history of sed
Shortcomings of sed
Performing substitutions
Performing line-specific substitutions: sed, Performing line-specific substitutions: Perl, Performing record-specific substitutions: Perl, Using backreferences and numbered variables in substitutions
Printing lines by number
Printing lines by number: sed, Printing lines by number: Perl, Printing records by number: Perl
Modifying templates
Converting special characters
Editing files
Editing with commands, Editing with scripts, Safeguarding in-place editing
Converting to lowercase or uppercase
Quieting spam
Substitutions with computed replacements
Converting miles to kilometers, Substitutions using function results
The sed to Perl translator
Summary
Directions for further study
5 Perl as a (better) awk command
A brief history of AWK
Comparing basic features of awk and Perl
Pattern-matching capabilities, Special variables, Perl's variable interpolation, Other advantages of Perl over AWK, Summary of differences in basic features
Processing fields
Accessing fields, Printing fields, Differences in syntax for print, Using custom field separators in Perl
Programming with Patterns and Actions
Combining pattern matching with field processing, Extracting data from tables, Accessing cell data using array indexing
Matching ranges of records
Operators for single- and multi-record ranges, Matching a range of dates, Matching multiple ranges
Using relational and arithmetic operators
Relational operators, Arithmetic operators
Using built-in functions
One-liners that use functions, The legend of nexpr, How the nexpr* programs work
Additional examples
Computing compound interest: compound_interest, Conditionally pluralizing nouns: compound_interest2, Analyzing log files: scan4oops
Using the AWK-to-Perl translator: a2p
Tips on using a2p
Summary
Directions for further study
6 Perl as a (better) find command
Introducing hybrid find / perl programs
File testing capabilities of find vs. Perl
Augmenting find with Perl
Finding files
Finding files by name matching, Finding files by pathname matching
Processing filename arguments
Defending against grep's messes, Recursive grepping, Perl as a generalized argument pre-processor
Using find | xargs vs. Perl alternatives
Using Perl for reliable timestamp sorting, Dealing with multi-word filenames
find as an argument pre-processor for Perl
A Unix-like, OS-portable find command
Making the most of find2perl, Helping non-Unix friends with find2perl
Summary
Directions for further study

Part 2 Minimal Perl: for UNIX and Linux Shell Programmers

7 Built-in functions
Understanding and managing evaluation context
Determinants and effects of evaluation context, Making use of evaluation context
Programming with functions that generate or process scalars
Using split, Using localtime, Using stat, Using chomp, Using rand
Programming with functions that process lists
Comparing Unix pipelines and Perl functions , Using sort, Using grep, Using join, Using map
Globbing for filenames
Tips on globbing
Managing files with functions
Handling multi-valued return codes
Parenthesizing function arguments
Controlling argument-gobbling functions
Summary
Directions for further study
8 Scripting techniques
Exploiting script-oriented functions
Defining defined, Exiting with exit, Shifting with shift
Pre-processing arguments
Accommodating non-filename arguments with implicit loops, Filtering arguments, Generating arguments
Executing code conditionally with if/else
Employing if/else vs. and/or, Mixing branching techniques: The cd_report script, Tips on using if/else
Wrangling strings with concatenation and repetition operators
Enhancing the most_recent_file script, Using concatenation and repetition operators together, Tips on using the concatenation operator
Interpolating command output into source code
Using the tput command, Grepping recursively: The rgrep script, Tips on using command interpolation
Executing OS commands using system
Generating reports, Tips on using system
Evaluating code using eval
Using a Perl shell: The psh script, Appreciating a multi-faceted Perl grepper: The preg script
Summary
Directions for further study
9 List variables
Using array variables
Initializing arrays with piecemeal assignments and push, Understanding advanced array indexing, Extracting fields in a friendlier fashion, Telling fortunes: The fcookie script, Tips on using arrays
Using hash variables
Initializing hashes, Understanding advanced hash indexing, Understanding the built-in %ENV hash, Printing hashes, Using %ENV in place of switches, Obtaining uniqueness with hashes, Employing a hash as a simple database: The user_lookup script, Counting word frequencies in web pages: The count_words script
Comparing list generators in the Shell and Perl
Filename generation/globbing, Command substitution/interpolation, Variable substitution/interpolation
Summary
Directions for further study
10 Looping facilities
Looping facilities in the Shell and Perl
Looping with while / until
Totaling numeric arguments, Reducing the size of an image, Printing key/value pairs from a hash using each, Understanding the implicit loop
Looping with do while / until
Prompting for input
Looping with foreach
Unlinking files: the rm_files script, Reading a line at a time, Printing a hash, Demystifying acronyms: The expand_acronyms script, Reducing image sizes: The compress_image2 script
Looping with for
Exploiting for's support for indexing: the raffle script
Using loop-control directives
Nesting loops within loops, Enabling loop-control directives in bottom-tested loops, Prompting for input, Enhancing loops with continue blocks: the confirmation script
The CPAN's select loop for Perl
Avoiding the re-invention of the "choose-from-a-menu" wheel, Monitoring user activity: the show_user script, Browsing man pages: the perlman script
Summary
Directions for further study
11 Subroutines and variable scoping
Compartmentalizing code with subroutines
Defining and using subroutines, Understanding use strict
Common problems with variables
Clobbering variables: The phone_home script, Masking variables: The 4letter_word script, Tips on avoiding problems with variables
Controlling variable scoping
Declaring variables with my , Declaring variables with our , Declaring variables with local, Introducing the Variable Scoping Guidelines
Variable Scoping Guidelines for complex programs
Enable use strict, Declare user-defined variables and define their scopes, Pass data to subroutines using arguments, Localize temporary changes to built-in variables with local, Employ user-defined loop variables ,Applying the Guidelines: the phone_home2 script
Reusing a subroutine
Summary
Directions for further study
12 Modules and the CPAN
Creating modules
Using the Simple Module Template, Creating a module: Center.pm, Testing a new module
Managing modules
Identifying the modules that you want, Determining whether you have a certain module, Installing modules from the CPAN
Using modules
Business::UPS-the ups_shipping_price script, LWP::Simple-the check_links script, Shell::POSIX::Select-the menu_ls script, File::Find-the check_symlinks script, CGI-the survey.cgi script, Tips on using Object-Oriented modules
Summary
Directions for further study

epilogue 426
appendix A: Perl special variables cheatsheet 427
appendix B: Guidelines for parenthesizing code 430
glossary 432
index 443 1

商品描述(中文翻譯)

描述

'如果你是 Unix/Linux 使用者並希望學習 Perl,我推薦這本書。'
-- George Wooley, Camelot.pm 和 Oakland.pm

'這本書不是 Perl 的小品,而是一個生存工具。'
-- William M. Julien, HPC Unix 性能分析師,財富 100 強公司

'不拖泥帶水且實用,卻又充滿智慧和魅力。閱讀的樂趣。'
-- Dan Sanderson, 軟體開發者

'展現風格,而不僅僅是事實,價值非凡。'
-- Brian Downs, 前 Lucent Technologies 培訓總監

'精彩,從不乏味,強烈推薦!'
-- Jon Allen, perldoc.perl.org 維護者

'你不可能找到比這本書更好的入門書。'
-- Damian Conway, 來自前言

Perl 是一種複雜的語言,掌握起來可能會很困難。Perl 的倡導者自豪地宣稱「有不止一種方法可以做到」,但你真的想學習多種方式來對電腦說同樣的話嗎?

為了讓 Perl 更加易於接觸,Tim Maher 博士多年來設計並教授了一個必要的語言子集,這個子集更小,但實用且強大。透過這本引人入勝的書,即使你對 Unix 只知道 grep,你也能受益於「Minimal Perl」。

你將學會如何編寫簡單的 Perl 命令(許多僅僅是一行),這些命令遠超過 Unix 工具的限制,以及 Linux、MacOS/X 等的限制。你還將利用對相關 Shell 資源的了解,獲得在腳本中使用的更高級的 Perl 技能。書中還穿插了許多針對 Unix 的 Perl 小技巧。

這本書特別適合系統管理員、網站管理員和軟體開發者。

目錄

前言
序言
致謝
關於本書
關於封面插圖
表格清單

Minimal Perl: 為 UNIX 和 Linux 使用者

1 介紹 Minimal Perl
造訪 Perlistan
有時你需要專業的指導
Perl 可以很簡單
關於 Minimal Perl
Minimal Perl 不是什麼,Minimal Perl 是什麼
懶惰是一種美德
最小的語法劑量
用分號結束語句
編寫一行程式
平衡簡單性和可讀性,實現簡單過濾器
總結

2 Perl 基礎
Perl 的調用選項
一行程式設計:-e,啟用警告:-w,處理輸入:-n,自動打印處理輸入:-p,處理行結尾:-l,無新行打印:printf,改變輸入記錄分隔符:-0digits
使用變數
使用特殊變數,使用數據變數:$_,使用記錄號變數:$., 使用用戶定義變數
載入模組 -M
編寫簡單腳本
引號技術,真和假值,處理開關:-s,使用 warn 和 die,使用邏輯與、邏輯或,使用 BEGIN 和 END 區塊編程,使用 load 模組
額外的特殊變數
使用 I/O 變數,利用格式化變數
標準選項集
使用別名來表示常見類型的 Perl 命令
構建程式
構建僅輸出的單行程式,構建輸入/輸出腳本
總結
進一步學習的指導

3 Perl 作為(更好的)grep 命令
grep 的簡史
grep 的缺點
對元字符的支持不確定,缺乏控制字符的字符串轉義,greppers 和 Perl 的比較
使用匹配運算符
單行 Perl grep
理解 Perl 的正則表達式符號
Perl 作為更好的 fgrep
僅顯示匹配,使用 $&
顯示不匹配的記錄(如 grep -v),驗證數據,使用快捷元字符最小化輸入
僅顯示檔名(如 grep -l)
使用匹配修飾符
忽略大小寫(如 grep -i)
Perl 作為更好的 egrep
使用級聯過濾器
在上下文中匹配
段落模式,檔案模式
使用正則表達式跨行匹配
跨行匹配,使用 lwp-request,過濾 lwp-request 輸出
額外示例
日誌檔分析,腳本化的 grep,模糊匹配,網頁抓取
總結
進一步學習的指導

4 Perl 作為(更好的)sed 命令
sed 的簡史
sed 的缺點
執行替換
執行行特定的替換:sed,執行行特定的替換:Perl,執行記錄特定的替換:Perl,使用回參考和編號變數進行替換
按行號打印
按行號打印:sed,按行號打印:Perl,按記錄號打印:Perl
修改模板
轉換特殊字符
編輯檔案
使用命令編輯,使用腳本編輯,保護就地編輯
轉換為小寫或大寫
安靜垃圾郵件
使用計算替換的替換
將英里轉換為公里,使用函數結果的替換
sed 到 Perl 的轉換器
總結
進一步學習的指導

5 Perl 作為(更好的)awk 命令
AWK 的簡史
比較 awk 和 Perl 的基本特徵
模式匹配能力,特殊變數,Perl 的變數插值,Perl 相對於 AWK 的其他優勢,基本特徵的差異總結
處理字段
訪問字段,打印字段,打印的語法差異,使用自定義字段分隔符在 Perl 中
使用模式和動作編程
將模式匹配與字段處理結合,從表中提取數據,使用數組索引訪問單元格數據
匹配記錄範圍
單記錄和多記錄範圍的運算符,匹配日期範圍,匹配多個範圍