Pro Perl Programming: From Professional to Advanced 9781484256046, 9781484256053, 1484256042

Master intermediate to advanced techniques of the Perl programming language starting with a focus on regular expressions

127 48 3MB

English Pages 344 [337]

Report DMCA / Copyright

DOWNLOAD PDF FILE

Table of contents :
Table of Contents
About the Author
About the Technical Reviewer
Chapter 1: Intermediate Regular Expressions
Review: Basic Regular Expressions
Basic operations
Basic modifiers
Basic metacharacters
Examples: The * and + characters
Examples: The { } characters
Examples: The ? character
Examples: The . character
Examples: The [ ] characters
Examples: The ^ and $ characters
Examples: The () characters
Examples: The | character
Examples: The \ character
Regular Expressions classes
Examples: "\w" and "\d"
Examples: "\s" and "\b"
Backreferencing
Example #1: Backreferencing
Example #2: Backreferencing
Example #3: Backreferencing
Modifiers
The e modifier
The d modifier
The s modifier
Other modifiers
Getting the Nth occurrence of a match
Greedy vs. non-greedy matches
Regular Expression variables
What was matched
Before and after what was matched
Warning about $&, $`, and $'
Special characters in Regular Expressions
Assertions
Looking forward and back
Using \G
Reading from filehandles using split
Multiple line matching
Using the s modifier
Using the \A, \Z, and \z assertions
Commenting Regular Expressions
Alternative delimiters
Additional resources
Lab exercises
Chapter 2: Advanced Regular Expressions
Make use of the Smartmatch operator
Using REs with Smartmatch
Additional Smartmatches
The given statement
Use Perl 5.10.1 or higher
Understand Regular Expression precedence
Understand what is *NOT* a Regular Expression atom
Using Regular Expressions in list context
Naming the capture variables within the pattern match
Match whitespace properly
Matching "end of the line"
Use \G
Use the \A, \Z, and \z assertions
Avoid capturing
Avoid the variables $`, $&, and $'
Method #1
Example using @-
Method #2
Compile your Regular Expressions before using them
Run time vs. compile time
Using qr to test user input
Using the o modifier
Benchmark your patterns
Use Regexp::Common
Flags you should consider always using
Automating /smx
Avoid escapes
Use the re pragma
use re'debug'
Understand backtracking
Additional resources
Lab exercises
Chapter 3: Advanced Features
Use my iterator variables with for loops
Foreach loops use local variable by default
Utilize loop labels
Avoid using for file matching
Time::HiRes
Contextual::Return
Indirect Filehandles
The three-argument technique to the open statement
Always check the return values of open, close, and when printing to a file
Close filehandles as soon as possible
Avoid slurping
Creatively use the do statement
Use the slurp() function
Test for interactivity
Use IO::Prompt
Understand where to find documentation
Sources of documentation
Understand context
Number vs. string
Scalar vs. array vs. list
Understand the => operator
Understand subroutine calls
Understand and/or vs. &&/||
Use Perl::Tidy
Use Perl::Critic
Understand Getopt::Std
Understand Getopt::Long
Alternative commenting technique
Passing notes within a Perl program
Use Smart::Comments
Additional resources
Lab exercises
Chapter 4: Advanced Formatted Output
Review: The format statement
The format statement
Placeholders
Repeating lines
Using select
Warning regarding the select statement
Advanced format statement features
Top of form
Format variables
Padding with zeros
Using ^*
printf and sprintf
Options for printf and sprintf
printf and sprintf flags
Example: Rounding numbers
Example: Modifying numbers
Example: Converting ASCII values
print sprintf
The Operator
Additional resources
Lab exercises
Chapter 5: Exploring Useful Built-in Variables
Variables reference chart
Use English
Status variables
The $? variable
The $! variable
The $^E variable
The $@ variable
Separator variables
Input record separator
Array separator variable
print separators
The signal handle variable
Version of Perl
Program start time
Additional resources
Lab exercises
Chapter 6: Advanced File Handling
Review: Basic file handling
Opening and reading from files
Opening and writing to files
Piping in Perl
Displaying the file position
Moving the file position
Opening files for reading and writing
Open an existing file for reading and writing
Truncating files
Why open a file for both reading and writing?
Making "files" within your script
Locking files
Flushing output buffers
Using select
Additional resources
Lab exercises
Chapter 7: Pragmas
Pragma chart
The use strict pragma
use strict'ref'
use strict'subs'
use strict'vars'
Predeclaring subroutines
Predeclaring global variables
Using new features
Example of use feature'say' and use feature'state'
Example of use feature "switch"
Using all features of a specific Perl version
Using locale
Final note about pragmas
Additional resources
Lab exercises
Chapter 8: Exploring Useful Built-in Modules
Built-in modules
Manipulate @INC at compile time
Determining the location of loaded modules
Loading modules as needed
Module table
Cwd
cwd
getcwd
fastcwd
Why not use a system statement?
Env
File modules
File::Basename
File::Compare
File::Copy
File::Path
File::Find
Additional useful file modules
Math modules
Math::BigFloat
Math::Trig
Additional useful math modules
Sys modules
Text
Text::Tabs
Text::Wrap
Fatal
Benchmark
Getopt::Std
Getopt::Long
Additional resources
Lab exercises
Chapter 9: Debugging Tools
Review: The -w switch
The $^W variable
use warnings
The -W switch
The -X switch
The Perl debugger
Debugger commands
Getting help
An alternative to print
Stepping through code
Listing code
Setting breakpoints
Listing breakpoints
Continue to breakpoints
Deleting breakpoints
Displaying variables and subroutines
Additional debuggers
Understanding error messages
use diagnostics
Carp
Using carp
Using croak
Data::Dumper
Perl style
Additional resources
Lab exercises
Chapter 10: Perl/TK Basics
The TK module
Types of widgets
Exploring widget examples
Geometry managers
Creating widgets
The OO nature of the Tk module
Additional resources
Lab exercises
Chapter 11: Perl TK Widgets
Frames
Relief
Colors
Labels
bitmaps
Using other images
text
Text wrapping
Buttons
Using buttons to exit your script
Using buttons to destroy widgets
Unpacking instead of destroying
Changing the cursor
Opening a toplevel
Lab
Checkbuttons
Radiobuttons
Padding
Listboxes
Using selected values
Selecting options
Scrollbars
Lab
Scales
Setting a default scale value
Entries
Hiding the user’s input
Disable an entry box
Creating menus
Creating the menu options
Adding radio options
Adding check options
Adding command options
Adding cascade and separators
Additional resources
Lab exercises
Chapter 12: Geometry Managers
The -after and -before option
The -anchor and -side options
-anchor vs. -side
The -fill option
Padding with pack
Managing widgets with pack
Binding
event
The focus command
Additional resources
Lab exercises
Index

Pro Perl Programming: From Professional to Advanced
 9781484256046, 9781484256053, 1484256042

  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
File loading please wait...
Recommend Papers