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 arrayRemove all elements from array (undef)Remove 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)Built 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 TimeDate and time using strftimeDate and time using Time::PieceEpoc date and timeDirectoriesList directoriesEmailEmail::Sender (send email)Net::SMTP (email)File::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 dataRead a file (<)Read and write to the same fileReplace values in a fileWrite to a file (> and >>)Files - 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) HashesHash (append values)Hash (count keys and values)Hash (define hash)Hash (determine if hash is defined)Hash (determine if hash key is defined)Hash (grep keys)Hash (lock_keys lock_values)Hash (multidimensional hash)Hash (remove keys)Hash (remove values)Hash (sort keys)Hash Array (append key value pairs multidimensional)Hash Array (append key value pairs) Hash Array (append keys)Hash Array (append values multidimensional)Hash Array (append values)Hash Array (count keys and values)Hash Array (create empty array)Hash Array (define hash)Hash Array (determine if hash array defined)Hash Array (remove values)loop hash (keys multidimensional)loop hash (keys)loop hash array (key value pairs)loop hash array (keys multidimensional)loop hash array (keys)loop hash array (values multidimensional )loop hash array (values)print hash valuesif elsif else statementsGetting Started with if elsif else statementsDetermine if a directory is emptyInstallInstall a module using cpanInstall a module using cpanmInstall 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 LoggerLoopsBreaking out of a loop (last)foreach 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 hexadecimal to decimalDivision (/)Multiplication (*)Subtraction (-)Sum of integers in a fileModulesCreate your own moduleDetermine if a module is installedOtherNative operating system command (`backticks`)Prompt a user for inputScientific notation with Microsoft ExcelPrinting 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 end of lineDo something every nth line in a fileDo something range of linesFlatten lists (merge similar lines)Match last occurrence of a line in a filenew lines (\n)Regular expression delimiterReplace text in a file (-pi -e =~)Trailing forward slashUsing grepwhitespace (\s)Returnreturn a hashreturn a stringreturn a variablereturn an arrayreturn in a subroutineSFTPGetting 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 Example.pm in @INC" in PerlResolve "Host key for has changed"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)Replace values in a variable (=~)XML::SimpleGetting 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 values (text)