FreeKB - Perl (Scripting) articles
Perl (Scripting) articles

ArraysGetting Started with ArraysAppend element to the beginning of an array (unshift)Append element to the end of an array (push)Count elements in an arrayCreate array over SSHDuplicate elements in an arrayPrint last value in an array in PerlRemove all elements from array (undef)Remove duplicate values from an arrayRemove element beginning of array (shift)Remove element from array (splice)Remove empty lines from arrayRemove first element from array (splice)Remove last element from an array (pop) Replace element in array (map)Sort arrayStore files directories in array (glob)BooleansGetting Started with BooleansBuilt in Perl commands%ENV environment special hashEscape special characters using quotemeta (\Q \E)eval functionLower case (lc)Random number generator (rand)scriptname $0Update 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 FlagsGetting Started with command line options and flagsCountCount characters in a string (length)Count lines in a file ($.)Data::DumperGetting Started with Data::DumperDate TimeAdd or subtract time using Time::Piece and Time::Seconds (timepiece)Date and time using localtimeDate and time using strftimeDate and Time using Time::Piece (timepiece)epoch date and timeDirectoriesList directoriesEmailNet::SMTP (email)Send email using Email::Sender and Email::MIMEFile::BasenameFile::Basename moduleFile::TouchGetting Started with File::TouchFilesPrevious, current, and next line in a file (seek, tell)Transfer a fileFiles - TXT / DOC / CSVDetermine if file contains a string of dataOpen file for reading (<)Open file for writing appending overwriting (> and >>)Read and write to the same fileReplace values in a fileFiles - XLSAppend or replace data in an Excel spreadsheet (Spreadsheet::ParseExcel)Read an Excel 95-2003 spreadsheet (xls) Write to an Excel 95-2003 spreadsheet (xls) HashAppend key value pairs to a hashAppend values to a hashCount keys and values in a hashDefine a hashDelete a key in a hashDetermine if a hash is definedDetermine if a key is defined in a hashLock keys and values in a hashLoop through keys in a hashLoop through values in a hashMatch keys in a hash using grepPrint values in a regular hashRemove value from a key in a hashSort keys in a hashHash (with array)Append key value pairs to a hash that contains an arrayAppend keys to a hash that contains an arrayAppend values to a hash that contains an arrayCount keys in a hash that contains an arrayCount values in a hash that contains an arrayDefine a hash that contains an arrayDefine hash that contains an arrayDetermine if an array in a hash is definedDetermine if an array in a hash is emptyLoop through key value pairs in an array in a hashLoop through keys in an array in a hashLoop through values in an array in a hashRemove all elements from an array in a hashRemove values from an array in a hashHash ReferenceAppend values to a reference hashAppend values to a reference hash that contains an arrayDefine a reference hashDetermine if a key is defined in a reference hashDetermine if a reference hash is definedPrint values in a reference hashif elsif else statementsGetting Started with if elsif else statementsDetermine if a directory is emptyInstallInstall Perl on LinuxJSONGetting Started with JSON::CreateGetting Started with JSON::ParseJSON Modification of a read-only valueJSON::Parse reason Not Found error Object Not FoundLoggerGetting Started with Log::Log4perl LoggerLoopsBreak out of a loopforeach loopsLoop through a file until line matchloop through a range of items in an arrayMoving onto next value in a loop (next)while loopMathAddition and Increment (+)Convert base 16 hexadecimal to decimalDivision (/)Multiplication (*)Subtraction (-)Sum of integers in a fileModulesCreate your own moduleDetermine if a module is installedInstall a module using cpanInstall a module using cpanmNative operating system commandsNative operating system command using `backticks` or systemOtherPrompt a user for input (stdin)Scientific notation with Microsoft ExcelPackagesGetting Started with PackagesPrinting outputBold text (Term::ANSIColor)Display text on the console (print and say)Regular Expressions (regex)( and ) charactersAppend leading zeros to numberscarriage returns (\r ^M)Dealing with Microsoft Word curly fancy smart quotesDo something beginning of line (^)Do something end of line ($)Do something every nth line in a fileDo something range of linesEscape literal dollar sign $Flatten lists (merge similar lines)match first all last occurrence of a patternMatch last occurrence of a line in a filenew lines \n and carriage returns \rRegular expression delimiterReplace text in a file (-pi -e =~)Trailing forward slashUsing grepwhitespace (\s)REST API (curl)Getting Started with the LWP::UserAgent REST API modulebasic authentication username password with the LWP::UserAgent REST API modulecurl HTTPS (LWP::UserAgent, LWP::Protocol::https)GET request with the LWP::UserAgent REST API moduleheaders with the LWP::UserAgent REST API moduleinsecure SSL certificates with the LWP::UserAgent REST API modulePOST data with the LWP::UserAgent REST API moduleReturnBreak out of a subroutine (return)return a hashreturn a stringreturn an arrayreturn one or more variablesReturn CodeReturn Code using systemSFTPGetting Started with Net::SFTPSpliting stringCut a string into pieces (substr)Split fields at delimiterSQL databaseConnect to a SQL databaseSSHGetting Started with Net::OpenSSHGetting Started with Net::SSH:PerlLocal and remote variables over SSHPublic key authentication with Net::SSH:PerlSubroutinesGetting Started with SubroutinesIdentical subroutine names (package, namespace)Pass values to a subroutine (@_ and $_ and shift)TroubleshootingResolve "Can't locate in @INC" in PerlResolve "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"Variables / ScalarsGetting Started with scalars and variablesAppend values to a variable (.=)Determine if a variable is definedDetermine if a variable is empty or nullGlobal and lexical variables (my and our)Replace values in a variable (=~) fileDefine the Portal Context Root (WpsContextRoot) in Workplace Properties file ( Started with XML::SimpleData::Dumper and XML::SimpleXML::Simple ArraysXML::Simple ForceArrayXML::Simple Ignore Attributes XML::Simple looping through hash keysXML::Simple looping through keysXML::Simple looping through keys that contain attributesXML::Simple output XML (XMLout)XML::Simple Printing AttributesXML::Simple printing keys (XMLin)XML::Simple printing values (XMLin)XML::Simple store XML in a variable (XMLin)XML::TwigXML::Twig change tag (set_tag)XML::Twig change value (set_text)XML::Twig loop through tags (first_child children)XML::Twig output to a fileXML::Twig parse XMLXML::Twig print attributesXML::Twig print values (text)