CINXE.COM
Perl tutorial
<!DOCTYPE html> <html lang="en-us"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes"> <link rel="canonical" href="https://perlmaven.com/perl-tutorial" /> <link rel="next" href="/installing-perl-and-getting-started"> <link href="/atom" rel="alternate" type="application/atom+xml" title ="Perl Maven" /> <script> var user_info = ; </script> <!-- Google recommended indication of translated versions --> <link rel="alternate" hreflang="x-default" href="https://perlmaven.com/perl-tutorial" /> <link rel="alternate" hreflang="ko" href="https://ko.perlmaven.com/perl-tutorial" /> <link rel="alternate" hreflang="es" href="https://es.perlmaven.com/perl-tutorial" /> <link rel="alternate" hreflang="he" href="https://he.perlmaven.com/perl-tutorial" /> <link rel="alternate" hreflang="de" href="https://de.perlmaven.com/perl-tutorial" /> <link rel="alternate" hreflang="fr" href="https://fr.perlmaven.com/perl-tutorial" /> <link rel="alternate" hreflang="en" href="https://perlmaven.com/perl-tutorial" /> <link rel="alternate" hreflang="pl" href="https://pl.perlmaven.com/perl-tutorial" /> <link rel="alternate" hreflang="ro" href="https://ro.perlmaven.com/perl-tutorial" /> <link rel="alternate" hreflang="zh-Hant" href="https://tw.perlmaven.com/perl-tutorial" /> <link rel="alternate" hreflang="ru" href="https://ru.perlmaven.com/perl-tutorial" /> <link rel="alternate" hreflang="cs" href="https://cs.perlmaven.com/perl-tutorial" /> <link rel="alternate" hreflang="it" href="https://it.perlmaven.com/perl-tutorial" /> <link rel="alternate" hreflang="tr" href="https://tr.perlmaven.com/perl-tutorial" /> <link rel="alternate" hreflang="pt" href="https://br.perlmaven.com/perl-tutorial" /> <link rel="alternate" hreflang="zh-Hans" href="https://cn.perlmaven.com/perl-tutorial" /> <link rel="alternate" hreflang="id" href="https://id.perlmaven.com/perl-tutorial" /> <link rel="alternate" hreflang="te" href="https://te.perlmaven.com/perl-tutorial" /> <title>Perl tutorial</title> <meta name="description" content="Free Perl Tutorial for people who need to maintain existing Perl code, for people who use Perl for small scripts, and for Perl application development."> <meta name="author" content="szabgab"> <!-- The Open Graph protocol --> <meta property="og:title" content="Perl tutorial"/> <meta property="og:type" content="article"/> <meta property="og:image" content="/img/perl_maven_150x212.png"/> <meta property="og:site_name" content="Perl Maven"/> <meta property="og:description" content="Free Perl Tutorial for people who need to maintain existing Perl code, for people who use Perl for small scripts, and for Perl application development."/> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css" rel="stylesheet"> <link href="/css/style.css?20210507.1" rel="stylesheet"> <link href="/static/css/site.css?20210507.1" rel="stylesheet"> <script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script> <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> <script src="/javascripts/perlmaven.js?20210507.1"></script> <script src="/js/maven.js"></script> <meta name="twitter:card" content="summary_large_image" /> <meta name="twitter:site" content="@szabgab" /> <meta name="twitter:creator" content="@szabgab" /> <meta name="twitter:title" content="Perl tutorial" /> <meta name="twitter:description" content="Free Perl Tutorial for people who need to maintain existing Perl code, for people who use Perl for small scripts, and for Perl application development." /> <meta name="twitter:image" content="/img/perl_maven_150x212.png" /> </head> <body> <div class="container-fluid"> <div class="row"> <div class="col-md-12"> <nav class="navbar navbar-default navbar-fixed-top navbar-inverse"> <div class="container-fluid"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="/">Perl Maven</a> </div> <div class="collapse navbar-collapse" id="navbar"> <ul class="nav navbar-nav "> <li><a href="/perl-tutorial">Perl Tutorial</a></li> <!-- --> <li><a href="/books">Books</a></li> <!-- --> </ul> <ul class="nav navbar-nav navbar-right "> <li><a href="/keywords">Type keyword:</a></li> <!-- --> <!-- --> <li><form id="search_form"> <input id="search_box" type="text" data-provide="typeahead" data-items="4" aria-label="Enter your search term"> </form> </li> <li><a href="/archive">Archive</a></li> <!-- --> <li><a href="/about">About</a></li> <!-- --> <!-- --> <li><a href="/atom" rel="alternate" type="application/atom+xml"><img src="/img/feed-icon16x16.png" id="atom-icon" alt="Atom feed" /></a></li> </ul> </div> </div> </nav> </div> </div> <div class="row"> <div class="col-md-2" id="left-column"> <div class="category_img"> <a href="https://perlmaven.com/perl-tutorial"><img src="/img/beginner_perl_maven_150x212.png" alt="Beginner Perl Maven tutorial" title="Beginner Perl Maven tutorial" /></a> </div> <div id="series"> <a href="/perl-tutorial">Perl tutorial</a> <span class="glyphicon glyphicon-ok"></span> <hr> <ol> <li>Introduction <ol> <li> <a href="/installing-perl-and-getting-started">Installing and getting started with Perl</a> </li> <li> <a href="/hashbang">The Hash-bang line, or how to make a Perl scripts executable on Linux</a> </li> <li> <a href="/perl-editor">Perl Editor</a> </li> <li> <a href="/help">How to get Help for Perl?</a> </li> <li> <a href="/perl-on-the-command-line">Perl on the command line</a> </li> <li> <a href="/core-perl-documentation-cpan-module-documentation">Core Perl documentation and CPAN module documentation</a> </li> <li> <a href="/pod-plain-old-documentation-of-perl">POD - Plain Old Documentation</a> </li> <li> <a href="/debugging-perl-scripts">Debugging Perl scripts</a> </li> </ol> </li> <li>Scalars <ol> <li> <a href="/common-warnings-and-error-messages">Common Warnings and Error messages in Perl</a> </li> <li> <a href="/read-from-stdin">Prompt, read from STDIN, read from the keyboard in Perl</a> </li> <li> <a href="/automatic-value-conversion-or-casting-in-perl">Automatic string to number conversion or casting in Perl</a> </li> <li> <a href="/if">Conditional statements, using if, else, elsif in Perl</a> </li> <li> <a href="/boolean-values-in-perl">Boolean values in Perl</a> </li> <li> <a href="/numerical-operators">Numerical operators</a> </li> <li> <a href="/string-operators">String operators: concatenation (.), repetition (x)</a> </li> <li> <a href="/undef-and-defined-in-perl">undef, the initial value and the defined function of Perl</a> </li> <li> <a href="/quoted-interpolated-and-escaped-strings-in-perl">Strings in Perl: quoted, interpolated and escaped</a> </li> <li> <a href="/here-documents">Here documents, or how to create multi-line strings in Perl</a> </li> <li> <a href="/scalar-variables">Scalar variables</a> </li> <li> <a href="/comparing-scalars-in-perl">Comparing scalars in Perl</a> </li> <li> <a href="/string-functions-length-lc-uc-index-substr">String functions: length, lc, uc, index, substr</a> </li> <li> <a href="/number-guessing-game">Number Guessing game</a> </li> <li> <a href="/while-loop">while loop</a> </li> <li> <a href="/scope-of-variables-in-perl">Scope of variables in Perl</a> </li> <li> <a href="/short-circuit">Short-circuit in boolean expressions</a> </li> </ol> </li> <li>Files <ol> <li> <a href="/how-to-exit-from-perl-script">How to exit from a Perl script?</a> </li> <li> <a href="/stdout-stderr-and-redirection">Standard output, standard error and command line redirection</a> </li> <li> <a href="/warn">Warning when something goes wrong</a> </li> <li> <a href="/die">What does die do?</a> </li> <li> <a href="/writing-to-files-with-perl">Writing to files with Perl</a> </li> <li> <a href="/appending-to-files">Appending to files</a> </li> <li> <a href="/open-and-read-from-files">Open and read from text files</a> </li> <li> <a href="/open-files-in-the-old-way">Don't Open Files in the old way</a> </li> <li> <a href="/reading-and-writing-binary-files">Reading and writing binary files in Perl</a> </li> <li> <a href="/end-of-file-in-perl">EOF - End of file in Perl</a> </li> <li> <a href="/tell">tell how far have we read a file</a> </li> <li> <a href="/seek">seek - move the position in the filehandle in Perl</a> </li> <li> <a href="/slurp">slurp mode - reading a file in one step</a> </li> </ol> </li> <li>Lists and Arrays <ol> <li> <a href="/for-loop-in-perl">Perl for loop explained with examples</a> </li> <li> <a href="/perl-arrays">Perl Arrays</a> </li> <li> <a href="/argv-in-perl">Processing command line arguments - @ARGV in Perl</a> </li> <li> <a href="/how-to-process-command-line-arguments-in-perl">How to process command line arguments in Perl using Getopt::Long</a> </li> <li> <a href="/advanced-usage-of-getopt-long-accepting-command-line-arguments">Advanced usage of Getopt::Long for accepting command line arguments</a> </li> <li> <a href="/perl-split">Perl split - to cut up a string into pieces</a> </li> <li> <a href="/how-to-read-a-csv-file-using-perl">How to read a CSV file using Perl?</a> </li> <li> <a href="/join">join</a> </li> <li> <a href="/the-year-19100">The year of 19100</a> </li> <li> <a href="/scalar-and-list-context-in-perl">Scalar and List context in Perl, the size of an array</a> </li> <li> <a href="/reading-from-a-file-in-scalar-and-list-context">Reading from a file in scalar and list context</a> </li> <li> <a href="/stdin-in-scalar-and-list-context">STDIN in scalar and list context</a> </li> <li> <a href="/sorting-arrays-in-perl">Sorting arrays in Perl</a> </li> <li> <a href="/sorting-mixed-strings">Sorting mixed strings</a> </li> <li> <a href="/unique-values-in-an-array-in-perl">Unique values in an array in Perl</a> </li> <li> <a href="/manipulating-perl-arrays">Manipulating Perl arrays: shift, unshift, push, pop</a> </li> <li> <a href="/reverse-polish-calculator-in-perl">Reverse Polish Calculator in Perl using a stack</a> </li> <li> <a href="/using-a-queue-in-perl">Using a queue in Perl</a> </li> <li> <a href="/reverse">Reverse an array, a string or a number</a> </li> <li> <a href="/the-ternary-operator-in-perl">The ternary operator in Perl</a> </li> <li> <a href="/loop-controls-next-last">Loop controls: next, last, continue, break</a> </li> <li> <a href="/min-max-sum-using-list-util">min, max, sum in Perl using List::Util</a> </li> <li> <a href="/qw-quote-word">qw - quote word</a> </li> </ol> </li> <li>Subroutines <ol> <li> <a href="/subroutines-and-functions-in-perl">Subroutines and functions in Perl</a> </li> <li> <a href="/passing-multiple-parameters-to-a-function">Passing multiple parameters to a function in Perl</a> </li> <li> <a href="/variable-number-of-parameters">Variable number of parameters in Perl subroutines</a> </li> <li> <a href="/returning-a-list-from-a-subroutine">Returning multiple values or a list from a subroutine in Perl</a> </li> <li> <a href="/recursive-subroutines">Understanding recursive subroutines - traversing a directory tree</a> </li> </ol> </li> <li>Hashes <ol> <li> <a href="/perl-hashes">Hashes in Perl</a> </li> <li> <a href="/creating-hash-from-an-array">Creating a hash from an array in Perl</a> </li> <li> <a href="/perl-hash-in-scalar-and-list-context">Perl hash in scalar and list context</a> </li> <li> <a href="/exists">exists - check if a key exists in a hash</a> </li> <li> <a href="/delete">delete an element from a hash</a> </li> <li> <a href="/how-to-sort-a-hash-in-perl">How to sort a hash in Perl?</a> </li> <li> <a href="/count-words-in-text-using-perl">Count the frequency of words in text using Perl</a> </li> </ol> </li> <li>Regular Expressions <ol> <li> <a href="/introduction-to-regexes-in-perl">Introduction to Regexes in Perl 5</a> </li> <li> <a href="/regex-character-classes">Regex character classes</a> </li> <li> <a href="/regex-special-character-classes">Regex: special character classes</a> </li> <li> <a href="/regex-quantifiers">Perl 5 Regex Quantifiers</a> </li> <li> <a href="/trim">trim - removing leading and trailing white spaces with Perl</a> </li> <li> <a href="/regex-cheat-sheet">Perl 5 Regex Cheat sheet</a> </li> </ol> </li> <li>Shell related functionality <ol> <li> <a href="/file-test-operators">What are -e, -z, -s, -M, -A, -C, -r, -w, -x, -o, -f, -d , -l in Perl?</a> </li> <li> <a href="/current-working-directory">Current working directory in Perl (cwd, pwd)</a> </li> <li> <a href="/running-external-programs-from-perl">Running external programs from Perl with system</a> </li> <li> <a href="/qx">qx or backticks - running external command and capturing the output</a> </li> <li> <a href="/how-to-remove-copy-or-rename-a-file-with-perl">How to remove, copy or rename a file with Perl</a> </li> <li> <a href="/reading-the-content-of-a-directory">Reading the content of a directory</a> </li> <li> <a href="/traversing-the-filesystem-using-a-queue">Traversing the filesystem - using a queue</a> </li> </ol> </li> <li>CPAN <ol> <li> <a href="/download-and-install-perl">Download and install Perl</a> </li> <li> <a href="/how-to-install-a-perl-module-from-cpan">Installing a Perl Module from CPAN on Windows, Linux and Mac OSX</a> </li> <li> <a href="/how-to-change-inc-to-find-perl-modules-in-non-standard-locations">How to change @INC to find Perl modules in non-standard locations</a> </li> <li> <a href="/how-to-add-a-relative-directory-to-inc">How to add a relative directory to @INC</a> </li> </ol> </li> <li>Examples for using Perl <ol> <li> <a href="/how-to-replace-a-string-in-a-file-with-perl">How to replace a string in a file with Perl</a> </li> <li> <a href="/read-an-excel-file-in-perl">How to read an Excel file in Perl</a> </li> <li> <a href="/create-an-excel-file-with-perl">How to create an Excel file with Perl?</a> </li> <li> <a href="/sending-html-email-using-email-stuffer">Sending HTML e-mail using Email::Stuffer</a> </li> <li> <a href="/perl-cgi-script-with-apache2">Perl/CGI script with Apache2</a> </li> <li> <a href="/json">JSON in Perl</a> </li> <li> <a href="/simple-database-access-using-perl-dbi-and-sql">Simple Database access using Perl DBI and SQL</a> </li> <li> <a href="/reading-from-ldap-in-perl-using-net-ldap">Reading from LDAP in Perl using Net::LDAP</a> </li> </ol> </li> <li>Common warnings and error messages <ol> <li> <a href="/global-symbol-requires-explicit-package-name">Global symbol requires explicit package name</a> </li> <li> <a href="/variable-declaration-in-perl">Variable declaration in Perl</a> </li> <li> <a href="/use-of-uninitialized-value">Use of uninitialized value</a> </li> <li> <a href="/barewords-in-perl">Barewords in Perl</a> </li> <li> <a href="/name-used-only-once-possible-typo">Name "main::x" used only once: possible typo at ...</a> </li> <li> <a href="/unknown-warnings-category">Unknown warnings category</a> </li> <li> <a href="/cant-use-string-as-a-hash-ref-while-strict-refs-in-use">Can't use string (...) as an HASH ref while "strict refs" in use at ...</a> </li> <li> <a href="/symbolic-reference-in-perl">Symbolic references in Perl</a> </li> <li> <a href="/cant-locate-in-inc">Can't locate ... in @INC</a> </li> <li> <a href="/scalar-found-where-operator-expected">Scalar found where operator expected</a> </li> <li> <a href="/my-variable-masks-earlier-declaration-in-same-scope">"my" variable masks earlier declaration in same scope</a> </li> <li> <a href="/cant-call-method-on-unblessed-reference">Can't call method ... on unblessed reference</a> </li> <li> <a href="/argument-isnt-numeric-in-numeric">Argument ... isn't numeric in numeric ...</a> </li> <li> <a href="/cant-locate-object-method-via-package-1">Can't locate object method "..." via package "1" (perhaps you forgot to load "1"?)</a> </li> <li> <a href="/useless-use-of-hash-element-in-void-context">Useless use of hash element in void context</a> </li> <li> <a href="/useless-use-of-private-variable-in-void-context">Useless use of private variable in void context</a> </li> <li> <a href="/readline-on-closed-filehandle">readline() on closed filehandle in Perl</a> </li> <li> <a href="/possible-precedence-issue-with-control-flow-operator">Possible precedence issue with control flow operator</a> </li> <li> <a href="/scalar-value-better-written-as">Scalar value ... better written as ...</a> </li> <li> <a href="/substr-outside-of-string">substr outside of string at ...</a> </li> <li> <a href="/have-exceeded-the-maximum-number-of-attempts">Have exceeded the maximum number of attempts (1000) to open temp file/dir</a> </li> <li> <a href="/use-of-implicit-split-to-is-deprecated">Use of implicit split to @_ is deprecated ...</a> </li> </ol> </li> <li>Other <ol> <li> <a href="/multi-dimensional-arrays-in-perl">Multi dimensional arrays in Perl</a> </li> <li> <a href="/multi-dimensional-hashes">Multi dimensional hashes in Perl</a> </li> <li> <a href="/minimal-requirement-to-build-a-sane-cpan-package">Minimal requirement to build a sane CPAN package</a> </li> <li> <a href="/statement-modifiers">Statement modifiers: reversed if statements</a> </li> <li> <a href="/autovivification">What is autovivification?</a> </li> <li> <a href="/printf">Formatted printing in Perl using printf and sprintf</a> </li> </ol> </li> </ol> </div> </div> <div class="col-md-7" id="content"> <div id="show_content"> <h1>Perl tutorial</h1> <div id="indexes"> <ul> </ul> </div> <div class="prev-next"> <h2> <span class="label label-lg label-success next"> <a href="/installing-perl-and-getting-started" title="Installing and getting started with Perl">Next <span class="glyphicon glyphicon-chevron-right"></span> </a> </span> </h2> </div> <div role="main" id="main"> <div id="top-poster"></div> <div id="abstract"> <div id="abstract_text"> </div> </div> <div id="after-abstract"></div> <h2>About this Tutorial and eBook</h2> <p> The Perl Maven tutorial will teach you the basics of the Perl programming language. You'll be able to write simple scripts, analyze log files and read and write CSV files. Just to name a few common tasks. <p> You'll learn how to use CPAN and several specific CPAN modules. <p> It will be a good foundation for you to build on. <p> If you are interested in getting updated when new parts are published, please <a href="/register">subscribe to the newsletter</a>. <p> There is also an <a href="https://leanpub.com/perl-maven/">e-book</a> version of the material available for purchase. In addition to the tutorial, the eBook also includes some material that is only available <a href="/pro">pro</a> subscribers. <p> <h2>Supporters</h2> <p> <a href="/perl-tutorial-supporters">Financial supporters of the Perl Tutorial</a> <p> <h2>Extended eBook</h2> <p> An extended version of the Perl Tutorial is available as an <a href="https://leanpub.com/perl-maven/">eBook</a>. It contains all the materials from the free tutorial and a number of additional articles that are only available to the <a href="/pro">Pro</a> subscribers. <p> <h2>Brand new or Legacy?</h2> <p> In every tutorial and in every book there is a tension between teaching the most modern techniques or teach how the legacy code works. <p> The most recent techniques will only be available to people who can use the most recent version of Perl. They are probably only relevant to new projects. People who need to use older versions of Perl or who cannot install modern CPAN modules will just get frustrated seeing all the nice stuff, but not able to use it. <p> The old techniques on the other hand will allow you to maintain existing applications and will allow you to write new applications on both old and new versions of Perl. The drawback here is that in many cases you might need to write more code, sometimes a lot more code, than you would if you used a recent version of Perl and recent CPAN modules. <p> This tutorial, and this eBook tries to provide a solution to this dilemma by providing both. Telling you about the alternative options and giving advice which one to use in which situation. <p> <h2>Video series</h2> <p> There is a free <a href="/beginner-perl-maven-video-course">video course</a> that includes over 210 screencasts, a total of more than 5 hours of video. In addition to presenting the material it also provides explanations to the solutions of all the exercise. <p> There is also a free <a href="/advanced-perl-maven-video-course">advanced Perl course</a>. <p> <h2>Free on-line Beginner Perl Maven tutorial</h2> <p> In this tutorial you are going to learn how to use the Perl 5 programming language to <b>get your job done</b>. <p> You will learn both general language features, and extensions or libraries or as the Perl programmers call them <b>modules</b>. We will see both standard modules, that come with perl and 3rd-party modules, that we install from <b>CPAN</b>. <p> When it is possible I'll try to teach things in a very task oriented way. I'll draw up tasks and then we'll learn the necessary tools to solve them. Where possible I'll also direct you to some exercises you can do to practice what you have learned. <p> <p> <b>Introduction</b> <ol> <li><a href="/installing-perl-and-getting-started">Install Perl, print Hello World, Safety net (use strict, use warnings)</a></li> <li><a href="/hashbang">#!/usr/bin/perl - the hash-bang line</a></li> <li><a href="/perl-editor">Editors, IDEs, development environment for Perl</a></li> <li><a href="/help">Getting Help</a></li> <li><a href="/perl-on-the-command-line">Perl on the command line</a></li> <li><a href="/core-perl-documentation-cpan-module-documentation">Core Perl documentation, CPAN module documentation</a></li> <li><a href="/pod-plain-old-documentation-of-perl">POD - Plain Old Documentation</a></li> <li><a href="/debugging-perl-scripts">Debugging Perl scripts</a></li> </ol> <p> <b>Scalars</b> <ol> <li><a href="/common-warnings-and-error-messages">Common warnings and error messages</a></li> <li><a href="/read-from-stdin">Prompt, read from STDIN, read from the keyboard</a></li> <li><a href="/automatic-value-conversion-or-casting-in-perl">Automatic string to number conversion</a></li> <li><a href="/if">Conditional statements: if</a></li> <li><a href="/boolean-values-in-perl">Boolean (true and false) values in Perl</a></li> <li><a href="/numerical-operators">Numerical operators</a></li> <li><a href="/string-operators">String operators</a></li> <li><a href="/undef-and-defined-in-perl">undef, the initial value and the defined function</a></li> <li><a href="/quoted-interpolated-and-escaped-strings-in-perl">Strings in Perl: quoted, interpolated and escaped</a></li> <li><a href="/here-documents">Here documents</a></li> <li><a href="/scalar-variables">Scalar variables</a></li> <li><a href="/comparing-scalars-in-perl">Comparing scalars</a></li> <li><a href="/string-functions-length-lc-uc-index-substr">String functions: length, lc, uc, index, substr</a></li> <li><a href="/number-guessing-game">Number Guessing game (rand, int)</a></li> <li><a href="/while-loop">Perl while loop</a></li> <li><a href="/scope-of-variables-in-perl">Scope of variables in Perl</a></li> <li><a href="/short-circuit">Boolean Short circuit</a></li> </ol> <p> <b>Files</b> <ol> <li><a href="/how-to-exit-from-perl-script">exit</a></li> <li><a href="/stdout-stderr-and-redirection">Standard Output, Standard Error and command line redirection</a></li> <li><a href="/warn">warn</a></li> <li><a href="/die">die</a></li> <li><a href="/writing-to-files-with-perl">Writing to files</a></li> <li><a href="/appending-to-files">Appending to files</a></li> <li><a href="/open-and-read-from-files">Open and read from files using Perl</a></li> <li><a href="/open-files-in-the-old-way">Don't open files in the old way</a></li> <li><a href="/reading-and-writing-binary-files">Binary mode - reading and writing binary files</a></li> <li><a href="/end-of-file-in-perl">eof, end of file in Perl</a></li> <li><a href="/tell">tell</a></li> <li><a href="/seek">seek</a></li> <li>truncate</li> <li><a href="/slurp">Slurp mode</a></li> </ol> <p> <b>Lists and Arrays</b> <ol> <li>Perl foreach loop</li> <li><a href="/for-loop-in-perl">The for loop in Perl</a></li> <li>Lists in Perl</li> <li>Using Modules</li> <li><a href="/perl-arrays">Arrays in Perl</a></li> <li><a href="/argv-in-perl">Process command line parameters @ARGV</a></li> <li><a href="/how-to-process-command-line-arguments-in-perl">Process command line parameters using Getopt::Long</a></li> <li><a href="/advanced-usage-of-getopt-long-accepting-command-line-arguments">Advanced usage of Getopt::Long for accepting command line arguments</a></li> <li><a href="/perl-split">split</a></li> <li><a href="/how-to-read-a-csv-file-using-perl">How to read and process a CSV file? (split, Text::CSV_XS)</a></li> <li><a href="/join">join</a></li> <li><a href="/the-year-19100">The year of 19100 (time, localtime, gmtime)</a> and introducing context</li> <li><a href="/scalar-and-list-context-in-perl">Context sensitivity in Perl</a></li> <li><a href="/reading-from-a-file-in-scalar-and-list-context">Reading from a file in scalar and list context</a></li> <li><a href="/stdin-in-scalar-and-list-context">STDIN in scalar and list context</a></li> <li><a href="/sorting-arrays-in-perl">Sorting arrays in Perl</a></li> <li><a href="/sorting-mixed-strings">Sorting mixed strings</a></li> <li><a href="/unique-values-in-an-array-in-perl">Unique values in an array in Perl</a></li> <li><a href="/manipulating-perl-arrays">Manipulating Perl arrays: shift, unshift, push, pop</a></li> <li><a href="/reverse-polish-calculator-in-perl">Stack</a></li> <li><a href="/using-a-queue-in-perl">Queue</a></li> <li><a href="/reverse">reverse</a></li> <li><a href="/the-ternary-operator-in-perl">The ternary operator</a></li> <li><a href="/loop-controls-next-last">Loop controls: next and last</a></li> <li><a href="/min-max-sum-using-list-util">min, max, sum using List::Util</a></li> <li><a href="/qw-quote-word">qw - quote word</a></li> </ol> <p> <b>Subroutines</b> <ol> <li><a href="/subroutines-and-functions-in-perl">Subroutines and Functions in Perl</a></li> <li><a href="/passing-multiple-parameters-to-a-function">Passing multiple parameters to a function</a></li> <li><a href="/variable-number-of-parameters">Variable number of parameters</a></li> <li><a href="/returning-a-list-from-a-subroutine">Returning a list, returning an array</a></li> <li><a href="/recursive-subroutines">Recursive subroutines</a></li> </ol> <p> <b>Hashes</b> <ol> <li><a href="/perl-hashes">Perl Hashes (dictionary, associative array, look-up table)</a></li> <li><a href="/creating-hash-from-an-array">Creating hash from an array</a></li> <li><a href="/perl-hash-in-scalar-and-list-context">Perl hash in scalar and list context</a></li> <li><a href="/exists">exists</a> hash element</li> <li><a href="/delete">delete</a> hash elements</li> <li><a href="/how-to-sort-a-hash-in-perl">Sorting a hash</a></li> <li><a href="/count-words-in-text-using-perl">Count word frequency in a text file</a></li> </ol> <p> <b>Regular Expressions</b> <ol> <li><a href="/introduction-to-regexes-in-perl">Introduction to Regular Expressions in Perl</a></li> <li><a href="/regex-character-classes">Regex: character classes</a></li> <li><a href="/regex-special-character-classes">Regex: special character classes</a></li> <li><a href="/regex-quantifiers">Regex: quantifiers</a></li> <li>Regex: Greedy and non-greedy match</li> <li>Regex: Grouping and capturing</li> <li>Regex: Anchors</li> <li>Regex options and modifiers</li> <li>Substitutions (search and replace)</li> <li><a href="/trim">trim - remove leading and trailing spaces</a></li> <li><a href="/regex-cheat-sheet">Perl 5 Regex Cheat sheet</a></li> </ol> <p> <b>Shell related functionality</b> <ol> <li><a href="/file-test-operators">Perl -X operators</a></li> <li>Perl pipes</li> <li>Unix commands: chmod, chown, cd, mkdir, rmdir, ln, ls</li> <li>Unix commands: <a href="/current-working-directory">pwd - current working directory</a></li> <li>Running external programs <a href="/running-external-programs-from-perl">using system</a></li> <li><a href="/qx">Capturning the output of an external program using qx or backticks</a></li> <li>Capturing output asynchronously</li> <li>Capturing both STDOUT and STDERR</li> <li>Unix commands: rm, mv, cp: <a href="/how-to-remove-copy-or-rename-a-file-with-perl">How to remove, copy or rename a file with Perl</a></li> <li>Windows/DOS commands: del, ren, dir</li> <li>File globbing (Wildcards)</li> <li><a href="/reading-the-content-of-a-directory">Directory handles</a></li> <li>Traversing directory tree <a href="/recursive-subroutines">manually with recursion</a></li> <li>Traversing directory tree <a href="/traversing-the-filesystem-using-a-queue">manually using a queue</a> and using find.</li> </ol> <p> <b>CPAN</b> <ol> <li><a href="/download-and-install-perl">Download and install Perl (Strawberry Perl or manual compilation)</a></li> <li>Download and install Perl using Perlbrew</li> <li>Locating and evaluating CPAN modules</li> <li><a href="/how-to-install-a-perl-module-from-cpan">Downloading and installing Perl Modules from CPAN</a></li> <li><a href="/how-to-change-inc-to-find-perl-modules-in-non-standard-locations">How to change @INC to find Perl modules in non-standard locations?</a></li> <li><a href="/how-to-add-a-relative-directory-to-inc">How to change @INC to a relative directory</a></li> <li>local::lib</li> </ol> <p> <b>Examples for using Perl</b> <ol> <li><a href="/how-to-replace-a-string-in-a-file-with-perl">How to replace a string in a file with Perl? (slurp)</a></li> <li><a href="/read-an-excel-file-in-perl">Reading Excel files using Perl</a></li> <li><a href="/create-an-excel-file-with-perl">Creating Excel files using Perl</a></li> <li><a href="/sending-html-email-using-email-stuffer">Sending e-mail using Perl</a></li> <li><a href="/perl-cgi-script-with-apache2">CGI scripts with Perl</a></li> <li>Parsing XML files</li> <li><a href="/json">Reading and writing JSON files</a></li> <li><a href="/simple-database-access-using-perl-dbi-and-sql">Database access using Perl (DBI, DBD::SQLite, MySQL, PostgreSQL, ODBC)</a></li> <li><a href="/reading-from-ldap-in-perl-using-net-ldap">Accessing LDAP using Perl</a></li> </ol> <p> <b>Common warnings and error messages</b> <ol> <li><a href="/global-symbol-requires-explicit-package-name">Global symbol requires explicit package name</a> ...</li> <li>.. also explained in <a href="/variable-declaration-in-perl">Variable declaration in Perl</a></li> <li><a href="/use-of-uninitialized-value">Use of uninitialized value</a></li> <li><a href="/barewords-in-perl">Bareword not allowed while "strict subs" in use</a></li> <li><a href="/name-used-only-once-possible-typo">Name "main::x" used only once: possible typo at ...</a></li> <li><a href="/unknown-warnings-category">Unknown warnings category</a></li> <li><a href="/cant-use-string-as-a-hash-ref-while-strict-refs-in-use">Can't use string (...) as a HASH ref while "strict refs" in use at ...</a> ...</li> <li>... explained in <a href="/symbolic-reference-in-perl">Symbolic references in Perl</a></li> <li><a href="/cant-locate-in-inc">Can't locate ... in @INC</a></li> <li><a href="/scalar-found-where-operator-expected">Scalar found where operator expected</a></li> <li><a href="/my-variable-masks-earlier-declaration-in-same-scope">"my" variable masks earlier declaration in same scope</a></li> <li><a href="/cant-call-method-on-unblessed-reference">Can't call method ... on unblessed reference</a></li> <li><a href="/argument-isnt-numeric-in-numeric">Argument ... isn't numeric in numeric ...</a></li> <li><a href="/cant-locate-object-method-via-package-1">Can't locate object method "..." via package "1" (perhaps you forgot to load "1"?)</a></li> <li><a href="/creating-hash-from-an-array">Odd number of elements in hash assignment</a></li> <li><a href="/qw-quote-word">Possible attempt to separate words with commas</a></li> <li><a href="/autoload">Undefined subroutine ... called</a></li> <li><a href="/useless-use-of-hash-element-in-void-context">Useless use of hash element in void context</a></li> <li><a href="/useless-use-of-private-variable-in-void-context">Useless use of private variable in void context</a></li> <li><a href="/readline-on-closed-filehandle">readline() on closed filehandle</a></li> <li><a href="/possible-precedence-issue-with-control-flow-operator">Possible precedence issue with control flow operator</a></li> <li><a href="/scalar-value-better-written-as">Scalar value better written as ...</a></li> <li><a href="/substr-outside-of-string">substr outside of string at ...</a></li> <li><a href="/have-exceeded-the-maximum-number-of-attempts">Have exceeded the maximum number of attempts (1000) to open temp file/dir</a></li> <li><a href="/deep-recursion-on-subroutine">Deep recursion on subroutine</a></li> <li><a href="/use-of-implicit-split-to-is-deprecated">Use of implicit split to @_ is deprecated ...</a></li> </ol> <p> <b>Extra articles</b> <ol> <li><a href="/multi-dimensional-arrays-in-perl">Multi dimensional arrays</a></li> <li><a href="/multi-dimensional-hashes">Multi dimensional hashes</a></li> <li><a href="/minimal-requirement-to-build-a-sane-cpan-package">Minimal requirement to build a sane CPAN package</a></li> <li><a href="/statement-modifiers">Statement modifiers: reversed if statements</a></li> <li><a href="/autovivification">autovivification</a></li> <li><a href="/printf">Formatted printing in Perl</a> using printf and sprintf</li> </ol> <p> <b>From other books</b> <ol> <li><a href="/splice-to-slice-and-dice-arrays-in-perl">Splice to slice and dice arrays in Perl</a></li> <li><a href="/how-to-improve-my-perl-program">How to improve your Perl code</a></li> </ol> <p> <b>Object Oriented Perl with Moose or Moo</b> <p> There is a whole series of articles on writing Object Oriented code, using the light-weight <a href="/moo">Moo</a> OOP framework or the full-blown <a href="/moose">Moose</a> OOP framework. <p> <hr> <p> There is a corresponding <a href="/beginner-perl-maven-video-course">video courses</a> and the whole tutorial is available as <a href="https://leanpub.com/perl-maven/">eBook</a>. <p> <div id="after-content"></div> </div> <div class="prev-next"> <h2> <span class="label label-lg label-success next"> <a href="/installing-perl-and-getting-started" title="Installing and getting started with Perl">Next <span class="glyphicon glyphicon-chevron-right"></span> </a> </span> </h2> </div> <hr> <div id="creators"> <img src="/img/szabgab.png" alt="Gabor Szabo" /> <!-- Gabor who runs the Perl Maven site helps companies set up <b>test automation</b>, CI/CD <b>Continuous Integration</b> and <b>Continuous Deployment</b> and other <b>DevOps</b> related systems. <p> Gabor can help refactor your old Perl code-base. <p> He runs the <a href="http://perlweekly.com/">Perl Weekly</a> newsletter. <p> <a href="https://szabgab.com/contact.html">Contact Gabor</a> if you'd like to hire his service. <p> Buy his <a href="https://leanpub.com/u/szabgab">eBooks</a> or if you just would like to support him, do it via <a href="https://www.patreon.com/szabgab">Patreon</a>. --> <div class="author_text"> Written by<br> <a href="https://www.linkedin.com/in/szabgab/">Gabor Szabo</a> </div> </div> <hr> <p> Published on 2013-07-16 </p> <div> If you have any comments or questions, feel free to post them on the source of this page in GitHub. <a href="https://github.com/szabgab/perlmaven.com/tree/main/sites/en/pages//perl-tutorial.txt">Source on GitHub.</a> <a href="https://github.com/szabgab/perlmaven.com/issues/new?title=&body=https://perlmaven.com/perl-tutorial">Comment on this post</a> </div> </div> </div> <div class="col-md-3"> <div id="right-side"> <div class="author-rightbox"> <h3>Author: Gabor Szabo</h3> <img src="/img/szabgab.png" alt="" /> Gabor who runs the Perl Maven site helps companies set up <b>test automation</b>, CI/CD <b>Continuous Integration</b> and <b>Continuous Deployment</b> and other <b>DevOps</b> related systems. <p> Gabor can help refactor your old Perl code-base. <p> He runs the <a href="http://perlweekly.com/">Perl Weekly</a> newsletter. <p> <a href="https://szabgab.com/contact.html">Contact Gabor</a> if you'd like to hire his service. <p> Buy his <a href="https://leanpub.com/u/szabgab">eBooks</a> or if you just would like to support him, do it via <a href="https://www.patreon.com/szabgab">Patreon</a>. </div> <div class="rightbox"> </div> <div class="rightbox"> <div id="sites"> <ul> <li> <a href="https://id.perlmaven.com/perl-tutorial">Bahasa Indonesia</a> </li> <li> <a href="https://de.perlmaven.com/perl-tutorial">Deutsch</a> </li> <li> <a href="https://perlmaven.com/perl-tutorial">English</a> <span class="glyphicon glyphicon-ok"></span> </li> <li> <a href="https://es.perlmaven.com/perl-tutorial">Español</a> </li> <li> <a href="https://fr.perlmaven.com/perl-tutorial">Français</a> </li> <li> <a href="https://it.perlmaven.com/perl-tutorial">Italiano</a> </li> <li> <a href="https://pl.perlmaven.com/perl-tutorial">Polish</a> </li> <li> <a href="https://br.perlmaven.com/perl-tutorial">Português</a> </li> <li> <a href="https://ro.perlmaven.com/perl-tutorial">Română</a> </li> <li> <a href="https://tr.perlmaven.com/perl-tutorial">Türkçe</a> </li> <li> <a href="https://cs.perlmaven.com/perl-tutorial">Čeština</a> </li> <li> <a href="https://ru.perlmaven.com/perl-tutorial">Русский</a> </li> <li> <a href="https://he.perlmaven.com/perl-tutorial">עברית</a> </li> <li> <a href="https://te.perlmaven.com/perl-tutorial">తెలుగు</a> </li> <li> <a href="https://tw.perlmaven.com/perl-tutorial">正體中文</a> </li> <li> <a href="https://cn.perlmaven.com/perl-tutorial">简体中文</a> </li> <li> <a href="https://ko.perlmaven.com/perl-tutorial">한국어</a> </li> <li><hr></li> <li><a href="https://perlmaven.com/about#translations">about the translations</a></li> </ul> </div> </div> <div class="rightbox"> </div> </div> </div><!-- end of right column --> </div> </div> <div id="modal"></div> <!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-BLRW8KB16K"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-BLRW8KB16K'); </script> </body> </html>