Bootstrap
<FreeKB>
Home
About
Walkthroughs
Perl (Scripting)
Profile
Sign in
FreeKB Articles
Perl (Scripting) articles
Arrays
Append element to the beginning of an array (unshift)
Append element to the end of an array (push)
Count elements in an array
Create array over SSH
Duplicate elements in an array
Getting Started with Arrays
Print last value in an array in Perl
Remove all elements from array (undef)
Remove duplicate values from an array
Remove element beginning of array (shift)
Remove element from array (splice)
Remove empty lines from array
Remove first element from array (splice)
Remove last element from an array (pop)
Replace element in array (map)
Sort array
Store files directories in array (glob)
Booleans
Getting Started with Booleans
Built in Perl commands
%ENV environment special hash
Escape special characters using quotemeta (\Q \E)
eval function
Lower case (lc)
Random number generator (rand)
scriptname $0
Update the first character in a string to be upper case (ucfirst)
Upper case (uc)
Variable contains (=~) or does not contain (!~)
Wrap text (Text::Wrap)
Command Line Options and Flags
Getting Started with command line options and flags
Count
Count characters in a string (length)
Count lines in a file ($.)
Data::Dumper
Getting Started with Data::Dumper
Date Time
Add or subtract time using Time::Piece and Time::Seconds (timepiece)
Date and time using localtime
Date and time using strftime
Date and Time using Time::Piece (timepiece)
epoch date and time
Directories
List directories
Email
Net::SMTP (email)
Send email using Email::Sender and Email::MIME
File::Basename
File and Directory basename and dirname
File::Touch
Getting Started with File::Touch
Files
Previous, current, and next line in a file (seek, tell)
Transfer a file
Files - TXT / DOC / CSV
Determine if file contains a string of data
Open file for reading (<)
Open file for writing appending overwriting (> and >>)
Read and write to the same file
Replace values in a file
Files - XLS
Append or replace data in an Excel spreadsheet (Spreadsheet::ParseExcel)
Read an Excel 95-2003 spreadsheet (xls)
Write to an Excel 95-2003 spreadsheet (xls)
Hash
Append key value pairs to a hash
Append values to a hash
Count keys and values in a hash
Define a hash
Delete a key in a hash
Determine if a hash is defined
Determine if a key is defined in a hash
Lock keys and values in a hash
Loop through keys in a hash
Loop through values in a hash
Match keys in a hash using grep
Print values in a regular hash
Remove value from a key in a hash
Sort keys in a hash
Hash (with array)
Append key value pairs to a hash that contains an array
Append keys to a hash that contains an array
Append values to a hash that contains an array
Count keys in a hash that contains an array
Count values in a hash that contains an array
Define a hash that contains an array
Define hash that contains an array
Determine if an array in a hash is defined
Determine if an array in a hash is empty
Loop through key value pairs in an array in a hash
Loop through keys in an array in a hash
Loop through values in an array in a hash
Remove all elements from an array in a hash
Remove values from an array in a hash
Hash Reference
Append values to a reference hash
Append values to a reference hash that contains an array
Define a reference hash
Determine if a key is defined in a reference hash
Determine if a reference hash is defined
Print values in a reference hash
Home
Home Directory
hostname
hostname
if elsif else statements
Determine if a directory is empty
Getting Started with if elsif else statements
if file contains match get next line
inline
Running commands inline
Install
Install Perl on Linux
JSON
Getting Started with JSON::Create
Getting Started with JSON::Parse
JSON Modification of a read-only value
JSON::Parse reason Not Found error Object Not Found
Lists
Count the number of elments in an list
Logger
Getting Started with Log::Log4perl Logger
Loops
Break out of a loop
foreach loops
Loop through a file until line match
loop through a range of items in an array
Moving onto next value in a loop (next)
while loop
Math
Addition and Increment (+)
Convert base 16 hexadecimal to decimal
Division (/)
Multiplication (*)
Subtraction (-)
Sum of integers in a file
Modules
Create your own module
Determine if a module is installed
Install a module using cpan
Install a module using cpanm
Native operating system commands
Native operating system command using `backticks` or system
Other
Prompt a user for input (stdin)
Scientific notation with Microsoft Excel
Packages
Getting Started with Packages
Printing output
Bold text (Term::ANSIColor)
Display text on the console (print and say)
Regular Expressions (regex)
( and ) characters
Append leading zeros to numbers
carriage returns (\r ^M)
Dealing with Microsoft Word curly fancy smart quotes
Do something beginning of line (^)
Do something end of line ($)
Do something every nth line in a file
Do something range of lines
Escape literal dollar sign $
Flatten lists (merge similar lines)
match first all last occurrence of a pattern
Match last occurrence of a line in a file
new lines \n and carriage returns \r
Regular expression delimiter
Replace text in a file (-pi -e =~)
Trailing forward slash
Using grep
whitespace (\s)
REST API (curl)
basic authentication username password with the LWP::UserAgent REST API module
curl HTTPS (LWP::UserAgent, LWP::Protocol::https)
GET request with the LWP::UserAgent REST API module
Getting Started with the LWP::UserAgent REST API module
headers with the LWP::UserAgent REST API module
insecure SSL certificates with the LWP::UserAgent REST API module
POST data with the LWP::UserAgent REST API module
Return
Break out of a subroutine (return)
return a hash
return a string
return an array
return one or more variables
Return Code
Return Code using system
SFTP
Getting Started with Net::SFTP
Spliting string
Cut a string into pieces (substr)
Split fields at delimiter
SQL database
Connect to a SQL database
SSH
Getting Started with Net::OpenSSH
Getting Started with Net::SSH::Perl
Local and remote variables over SSH
Public key authentication with Net::SSH::Perl
Subroutines
Getting Started with Subroutines
Identical subroutine names (package, namespace)
Pass values to a subroutine (@_ and $_ and shift)
Troubleshooting
Global symbol requires explicit package name
Resolve "Can't locate Example.pm in @INC" in Perl
Resolve "Experimental keys on scalar is now forbidden"
Resolve "Host key for has changed"
Resolve "JSON Error Empty input parsing initial state"
Resolve "Reference found where even-sized list expected"
Resolve "Variable will not stay shared"
Resolve "Wrong key type"
Variables / Scalars
Append values to a variable (.=)
Determine if a variable is defined
Determine if a variable is empty or null
Getting Started with scalars and variables
Global and lexical variables (my and our)
Replace values in a variable (=~)
wkplc.properties file
Define the Portal Context Root (WpsContextRoot) in Workplace Properties file (wkplc.properties)
XML::Simple
Data::Dumper and XML::Simple
Getting Started with XML::Simple
XML::Simple Arrays
XML::Simple ForceArray
XML::Simple Ignore Attributes
XML::Simple looping through hash keys
XML::Simple looping through keys
XML::Simple looping through keys that contain attributes
XML::Simple output XML (XMLout)
XML::Simple Printing Attributes
XML::Simple printing keys (XMLin)
XML::Simple printing values (XMLin)
XML::Simple store XML in a variable (XMLin)
XML::Twig
XML::Twig change tag (set_tag)
XML::Twig change value (set_text)
XML::Twig loop through tags (first_child children)
XML::Twig output to a file
XML::Twig parse XML
XML::Twig print attributes
XML::Twig print values (text)