How To Properly Specify Command and Arguments to Exec in Perl

Author: , December 11th, 2019

When using Perl’s exec() call, the best way to invoke it is as follows:

This syntax does some important things: – passes a scalar value as the first argument which exec interprets as PROGRAM – passes an array as the second argument which exec will use as the arguments to pass into PROGRAM Note […]

How To Read Multiple Lines of User Input from the Command Line in Perl

Author: , October 9th, 2019

Use Case: Export Apple Reminders from MacOS application to cleaned plain text, i.e. remove unwanted spaces, blank lines and square brackets PROCEDURE Click on a single item in the MacOS Reminders app list Select All (either Command-a or use Edit->Select All) Copy (either Command-c or use Edit->Copy) Open Terminal Run cleanme Paste the copied reminders […]

How To Enable Variable References in Perl While Using Strict

Author: , August 4th, 2019

I wanted to call a sub-routine based on a variable in Perl, like this:

but it failed because of use strict:

To enable using a variable as a reference, simply specify that to Perl:

How To Install/Update CPAN on MacOS Mojave with fatal error: ‘EXTERN.h’ file not found

Author: , June 12th, 2019

The Problem Tried to install the latest version of cpan and got stuck. Tracked it down to the dependency module Mac::SystemDirectory which was failing to build:

The Solution Use the MacOS installer command to deploy the needed files:

The, rerunning the cpan install works:

How To Use Regex Negative Lookahead To Exclude Strings

Author: , May 31st, 2019

I have a task in Perl to list specific files based on pattern match, those with and those without the string “_from_”. There are two files in the directory to filter: static-east.properties static-east_from_west.properties To capture the files with the _from_ string was easy:

To capture the files WITHOUT the _from_ string was not quite […]

How To Reformat or Re-indent Files in VIM

Author: , January 11th, 2019

In the normal vim mode, typing gg=G will reindent the entire file. == will re-indent just the current line. http://vim.wikia.com/wiki/Fix_indentation

How To Calculate Dates In Perl Using Date::Manip

Author: , September 18th, 2017

How To Watch https Calls to Apache 2.4 using Perl and mod_status

Author: , September 5th, 2017

Step 1: Enable Apache status and lock it down: Make sure mod_status is being loaded:

Add support for the call just under the first DocumentRoot statement:

Step 2. Prepare your environment:

Step 3: Create and run the status script: (See the astat contents at the bottom)

/root/astat

How To Batch Search and Replace Multiple Files Using PERL

Author: , October 16th, 2014

Using PERL, we can easily do a search and replace across multiple files. perl -pi -w -e ‘s/SEARCH_FOR/REPLACE_WITH/g;’ FILE_LIST The following example will replace all occurrences of “hello” with “goodbye” inside files ending with .txt:

To handle special characters, use the hex value. For example, to convert MS web files that use control characters: […]

How To Force Getopt::Long To Be Case Sensitive in Perl

Author: , March 19th, 2014