\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{SathyaNarayanan (Sathyanarayanan)} \pdfinfo{ /Title (perl-shortcuts.pdf) /Creator (Cheatography) /Author (SathyaNarayanan (Sathyanarayanan)) /Subject (Perl shortcuts Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{9863A3} \definecolor{LightBackground}{HTML}{F8F5F9} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Perl shortcuts Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{SathyaNarayanan (Sathyanarayanan)} via \textcolor{DarkBackground}{\uline{cheatography.com/136085/cs/28347/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}SathyaNarayanan (Sathyanarayanan) \\ \uline{cheatography.com/sathyanarayanan} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 19th June, 2021.\\ Updated 17th June, 2021.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{4} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Documentation}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{=pod \newline % Row Count 1 (+ 1) my \$dog = "hatchi"; \newline % Row Count 2 (+ 1) my \$cat = "meow"; \newline % Row Count 3 (+ 1) =cut% Row Count 4 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.65227 cm} x{2.78073 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Logical Operators}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{Logical} & or, and, xor, not, ||, \&\&, ! \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \seqsplit{Strings} & eq, gt, lt, le, ge, cmp \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \seqsplit{Numbers} & ==, \textless{},\textgreater{},\textless{}=,\textgreater{}=,\textless{}=\textgreater{} \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{File Test Operators}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{-e exists \newline % Row Count 1 (+ 1) -r readable \newline % Row Count 2 (+ 1) -w writable \newline % Row Count 3 (+ 1) -d directory \newline % Row Count 4 (+ 1) -f file \newline % Row Count 5 (+ 1) -T Text file% Row Count 6 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Conditions}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Unless \newline % Row Count 1 (+ 1) if \{ \} \newline % Row Count 2 (+ 1) elsf\{\} \newline % Row Count 3 (+ 1) else\{\} \newline % Row Count 4 (+ 1) given() \{ when \{ \} \}% Row Count 5 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{2.84939 cm} p{0.58361 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Regular expression}} \tn % Row 0 \SetRowColor{LightBackground} Whitespace & \textbackslash{}s \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} word & \textbackslash{}w \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} Digit & \textbackslash{}d \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} Non digit & \textbackslash{}D \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} Beginning & \textasciicircum{} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} End & \$ \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{/\textbackslash{}bFred\textbackslash{}b/ matches whole word \newline Next LINE if \$line=/\textasciicircum{}\#/;} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{2.12846 cm} x{1.30454 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Quantifiers}} \tn % Row 0 \SetRowColor{LightBackground} min, max & \textbackslash{}d\{min, max\} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} 7 to 11 digit & \textbackslash{}d\{7,11\} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} Only matches 7 digit & \textbackslash{}d\{7\} \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{+, *, ? . \newline \{\} quantifiers applies to single character \newline () store in memory \newline s/(S+)s+(S+)/\$2 \$1/} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{LIST processing}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{print reverse sort map\{lc\} keys \%hash \newline % Row Count 1 (+ 1) To parse a string 12:59:59 am \newline % Row Count 2 (+ 1) -my (\$hour, \$min, \$sec, \$ampm)=/(\textbackslash{}d+): (\textbackslash{}d+) : (\textbackslash{}d+) * (\textbackslash{}w+)/% Row Count 4 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Terms and List Operator}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{|| has lower precedence than chdir% Row Count 1 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{chdir \$foo || die \#(chdir \$foo) || die \newline chdir(\$foo) || die \#(chdir \$foo) || die \newline chdir +(\$foo) || die \#(chdir \$foo) || die} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Evalvuation}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{print(\$foo, exit) \# Obviously not what you want \newline % Row Count 1 (+ 1) print \$foo, exit \#nor this% Row Count 2 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{These do the print before evaluating exit. \newline \newline (print \$foo), exit \newline or \newline print (\$foo), exit} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{File test operator}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/sathyanarayanan_1623845727_Picture2.jpg}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Total seconds /day = 86400 \newline 5 Minutes = 300 \newline 12 hour = 300 {\emph{12 }} 12 = 43200 \newline Total hour= 12 hr/86400 = 0.5 \newline -M \$finename \textgreater{} 0.5 \#greated than 12 hours \newline -M \$finename \textgreater{} 0.5 \#recently modified file \newline \&callfunction If int( -A \$filename) == 90} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Tricks}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Sub setenv\{ \newline my (\$key, \$value)=@\_; \newline \$ENV\{\$key)=\$value unless \$ENV\{\$key\} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Initialization}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{BEGIN \{ \newline my @scale = ("A" .. "G"); \newline my \$note = –1; \newline sub next\_pitch \{ return \$scale{[} (\$note += 1) \%= @scale {]} \}; \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{It will execute before your program starts} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Handle reference}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{for \$file(@names)\{ \newline my \$fh; \newline open(\$fh, \$file) || next; \newline \$filehandle\{\$file\}=\$fh; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Symbol table reference}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{\$scalarref= {\emph{foo\{SCALAR\} \# \textbackslash{}\$foo \newline \$arrayref=}}ARGV\{ARRAY\} \# \textbackslash{}@ARGV \newline \$hashref = {\emph{ENV\{HASH\}; \# \textbackslash{}\%ENV \newline \$coderef=}}handler\{CODE\} \# \textbackslash{}\&handler \newline \$gobref={\emph{foo\{GLOB\} \newline \$ioref=}}STDIN\{IO\}; \newline \$format=*foo\{FORMAT\};} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{protection}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{use strict "refs"} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{block counterman the decree with \newline no strict "refs"} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Symbolic reference example:}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{our \$value = "global"; \{ \newline my \$value = "private"; \newline print "Inside, mine is \$\{value\}, "; say "but ours is \$\{"value"\}."; \newline \} \newline say "Outside, \$\{value\} is again \$\{"value"\}.";} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{which prints: \newline Inside, mine is private, but ours is global. Outside, global is again global. \newline \newline Package variables are global variable} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Variables}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{\$days : simple scalar value \newline % Row Count 1 (+ 1) \$days{[}28{]} : 29 elements \newline % Row Count 2 (+ 1) \$days\{"feb"\} value from hash days \newline % Row Count 3 (+ 1) \$\{day\}. Equvalent to \$day \newline % Row Count 4 (+ 1) \$Dog;:day; from Dog package \newline % Row Count 5 (+ 1) \$\#days last index of array \#days \newline % Row Count 6 (+ 1) \$days-\textgreater{}{[}28{]} 29 the element pointed to by reference \newline % Row Count 8 (+ 2) \$days{[}0{]}{[}2{]} multi dim array \newline % Row Count 9 (+ 1) \$days\{2000\}\{"feb"\} mult dim hash \newline % Row Count 10 (+ 1) \$days\{200,"feb"\} multi dimensional hash emulation \newline % Row Count 12 (+ 2) @days : array containing (\$day{[}0{]}, \$day{[}1{]}….\$day{[}N{]}) \newline % Row Count 14 (+ 2) @days{[}3,4,5{]} :array containing (\$day{[}3{]}, \$day{[}4{]}, 4day{[}5{]}) \newline % Row Count 16 (+ 2) @days{[}3..5{]}: array containing (\$day{[}3{]}, \$day{[}4{]},\$day{[}5{]}) \newline % Row Count 18 (+ 2) @days\{"Jan", "Feb"\}: hash containing (\$days\{"Jan"\}, \$days\{"feb"\}) \newline % Row Count 20 (+ 2) \$days\{"feb"\} equvalent to \$days\{feb\}% Row Count 21 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Name space}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Lexical scope: block \newline % Row Count 1 (+ 1) Symbol table : global \newline % Row Count 2 (+ 1) Tips: \newline % Row Count 3 (+ 1) \$foo, @foo can be declared \newline % Row Count 4 (+ 1) In same block, \newline % Row Count 5 (+ 1) \$foo{[}0{]} is different from \$foo% Row Count 6 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{CommandLine}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Perl -E 'say 10/3'; \newline % Row Count 1 (+ 1) Perl-Mbigrat. -E 'sat 4/3. * 5/12'% Row Count 2 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Truth}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{String True except for " " and "0" \newline % Row Count 1 (+ 1) Number true except for 0 \newline % Row Count 2 (+ 1) Any reference is true \newline % Row Count 3 (+ 1) Any undefined value is false.% Row Count 4 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Tips}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{\$" is equal to space " " \newline % Row Count 1 (+ 1) \$temp=join(\$", @array); \newline % Row Count 2 (+ 1) Or \newline % Row Count 3 (+ 1) \$temp=join(" ", @array);% Row Count 4 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.75526 cm} x{2.67774 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Quote Construct}} \tn % Row 0 \SetRowColor{LightBackground} q// & ' ' \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} qq// & " " \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} qx/ / & Command exec \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} qw// & WordList \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} m// & Pattern match \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} s// & Substitute \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} y/// & Translation \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} Qr// & Regular Expression \tn % Row Count 8 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Auto Increment and Decrement}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{++\$b\{/(\textbackslash{}w+)/\}{[}0{]}\} \newline % Row Count 1 (+ 1) \# increment the element hash indexed by word in the default \newline % Row Count 3 (+ 2) search variable (\$\_)and return after increment.% Row Count 4 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{my \$foo; \newline \$foo= "99"; print ++ \$foo ; \#prints 100 \newline \$foo="Az"; print ++ \$foo ; \#prints Ba} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Binding operator}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{\$string ! \textasciitilde{} /\$pattern/ \newline % Row Count 1 (+ 1) ! (\$string =\textasciitilde{} /\$pattern/) \newline % Row Count 2 (+ 1) not (\$string =\textasciitilde{} /\$pattern/)% Row Count 3 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{\textasciitilde{} is after =} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Equality Operator}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/sathyanarayanan_1623846899_Picture4.jpg}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{cmp : return -1 if left operand is less than right, 0 If it is equal, 1 if left operand is greater than right.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{smartwatch operator}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/sathyanarayanan_1623846982_Picture5.jpg}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{my \%hash = (red =\textgreater{} 1, blue =\textgreater{} 2, green =\textgreater{} 3, orange =\textgreater{} 4, yellow =\textgreater{} 5, purple =\textgreater{} 6, \newline black =\textgreater{} 7, grey =\textgreater{} 8, white =\textgreater{} 9); \newline my @array = qw(red blue green); \newline print "some element in hash" if @array \textasciitilde{}\textasciitilde{} \%hash;} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Reference}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{@tailings=popmany(\textbackslash{}@a, \textbackslash{}@a2, \textbackslash{}@a3); \newline Sub popmany\{ \newline my @retlist=() \newline for my \$ref (@\_) \{ \newline push @retlist @\$ref; \newline \} \newline return @retlist; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{If you want to pass more than one array and hashes to the function you might have to use pass by reference, it saves the time and space} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Hash of Hash}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{\%table= ( \newline 'john' =\textgreater{} \{age =\textgreater{}47, eyes=\textgreater{}'brown', weight=\textgreater{}186\}, \newline 'Mary'=\textgreater{}\{age=\textgreater{}23, eyes=\textgreater{}'hazel', weight=\textgreater{}128\} \newline ); \newline \newline print \$table\{john\}\{age\}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Prints 47} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Operator: ref}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Ref operator to determine what a reference is pointing. \newline % Row Count 2 (+ 2) SCALAR, ARRAY, HASH, CODE, GLOB, REF, VSTRING, IO, LVALUE, FORMAT, REGEXP% Row Count 4 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Symbolic reference}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{\$name="bam"; \newline \$\$name=1; \#sets \$bam \newline \$name-\textgreater{}{[}0{]}=4; \newline \#set the first element of @bam \newline \$name-\textgreater{}\{X\}="Y" \#sets the X element of Y \newline @\$name=() \#resets the @bam \newline \&\$name \#calls the function bam} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Status}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{\$\$ current process id \newline % Row Count 1 (+ 1) \$? Exits status% Row Count 2 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Context}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Scalar: \newline % Row Count 1 (+ 1) \$x = funkshun() \newline % Row Count 2 (+ 1) \$x{[}1{]} = funkshun() \newline % Row Count 3 (+ 1) \$x\{"ray"\}= funkshun() \newline % Row Count 4 (+ 1) List: \newline % Row Count 5 (+ 1) @x= funkshun(); \newline % Row Count 6 (+ 1) @x{[}1{]}= funkshun(); \newline % Row Count 7 (+ 1) @ax\{"ray"\}= funkshun() \newline % Row Count 8 (+ 1) \%x= funkshun() \newline % Row Count 9 (+ 1) (\$x, \$y, \$z)= funkshun() \newline % Row Count 10 (+ 1) (\$x)= funkshun() \newline % Row Count 11 (+ 1) my \$x= funkshun() \#scalar context \newline % Row Count 12 (+ 1) my (\$x)= funkshun(). \# list context \newline % Row Count 13 (+ 1) Boolean: \newline % Row Count 14 (+ 1) @x; gives number of elements \newline % Row Count 15 (+ 1) While(@x)\{ \newline % Row Count 16 (+ 1) \$file=Shift(@x); \newline % Row Count 17 (+ 1) unlink(\$file) || warn. "couldn't delete file"; \newline % Row Count 19 (+ 2) \}% Row Count 20 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.7165 cm} x{1.7165 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{List values and arrays}} \tn % Row 0 \SetRowColor{LightBackground} @stuff=("one", "two", "three") & Assign entire list to array \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \$stuff=("one", "two", "three") & "three" is assigned to stuff \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} \$stuff=@stuff; & \$stuff is assigned to length of the array i.e 3 \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} @releases=("alpha", "beta", "gamma",) & Comma is allowed in the last. \tn % Row Count 12 (+ 3) % Row 4 \SetRowColor{LightBackground} \$modificationtime=(stat(\$file)){[}9{]}; & Modification time \tn % Row Count 14 (+ 2) % Row 5 \SetRowColor{white} \$hexdigit=("a","b","c","d",){[}\$digit-10{]} & hexdigit \tn % Row Count 17 (+ 3) % Row 6 \SetRowColor{LightBackground} (\$day, \$month, \$year)=(localtime){[}3, 4,5{]}; & day/month/year \tn % Row Count 20 (+ 3) % Row 7 \SetRowColor{white} @days + 0; & implicit forces array into scalar \tn % Row Count 22 (+ 2) % Row 8 \SetRowColor{LightBackground} scalar(@days) & explicit r @days into scalar \tn % Row Count 24 (+ 2) % Row 9 \SetRowColor{white} @whatever=() & \$\#whatever=-1 \tn % Row Count 25 (+ 1) % Row 10 \SetRowColor{LightBackground} undef(@whatever) & recover its memory \tn % Row Count 26 (+ 1) % Row 11 \SetRowColor{white} scalar(@whatever) & \$\# whatever + 1; \tn % Row Count 27 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.64784 cm} x{1.78516 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Multiplicative operator}} \tn % Row 0 \SetRowColor{LightBackground} print "-" x 80 & prints row of dashes. \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} my @ones = (1) x 80; & list of 80 1's; \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} @ones = (5) x @ones & \#set all elements to 5 \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.6866 cm} x{2.7464 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Array, Hash initialization:}} \tn % Row 0 \SetRowColor{LightBackground} my \%hash & @hash(@keys) = (" ") x @keys; \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} my @keys & @keys=qw( perl doc yyy); \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{Result: \newline \$hash\{perl\}=""; \newline \$hash\{doc\}=""; \newline \$hash\{yyy\}=""} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Short circuit operator}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{\$a \&\& \$b or \$a and \$b \newline % Row Count 1 (+ 1) \$a || \$b or \$a or \$b \newline % Row Count 2 (+ 1) \$a // \$b \#define OR% Row Count 3 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{\$pid=fok() // die ''can't fork \$!'' \newline \$value = \$hash\{value\} // "DEFAULT"} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Conditional operator}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{my \$a = \$ok ? \$a: \$b \newline % Row Count 1 (+ 1) my @a=\$ok? @a:@b; \newline % Row Count 2 (+ 1) ( \$a\_or\_b ? \$a:\$b)=\$c% Row Count 3 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{miscellaneous}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{State : state variable is never initialized and restricted to scalar vairables. \newline % Row Count 2 (+ 2) use v5.18; \newline % Row Count 3 (+ 1) sub next\_count\{ \newline % Row Count 4 (+ 1) state \$counter=0; \newline % Row Count 5 (+ 1) return ++\$counter; \newline % Row Count 6 (+ 1) \} \newline % Row Count 7 (+ 1) print (next\_count()); \newline % Row Count 8 (+ 1) print (next\_count()); \newline % Row Count 9 (+ 1) print (next\_count()); \newline % Row Count 10 (+ 1) Output: 1,2,3 \newline % Row Count 11 (+ 1) Our: access the global variable \newline % Row Count 12 (+ 1) sub check\_warehouse \{ \newline % Row Count 13 (+ 1) our @Current\_Inventory; \newline % Row Count 14 (+ 1) my \$widget; \newline % Row Count 15 (+ 1) foreach \$widget (@Current\_Inventory) \{ \newline % Row Count 16 (+ 1) say "I have a \$widget in stock today."; \} \newline % Row Count 17 (+ 1) \} \newline % Row Count 18 (+ 1) our keyword changes the global variable \newline % Row Count 19 (+ 1) local: it changes the variable value locally even if it uses the global name and it will not change the gloal variable value. \newline % Row Count 22 (+ 3) Subroutines \newline % Row Count 23 (+ 1) To declare named subroutine without defining \newline % Row Count 24 (+ 1) Sub Name Sub Name Proto Sub Name Proto attr% Row Count 28 (+ 4) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Tricks2}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{@reflist = ( \textbackslash{}\$s, \textbackslash{}@a, \textbackslash{}\%h) \newline Is equal to \newline @reflist=\textbackslash{}(\$s, @a, \%h) \newline \newline \newline @reflist=\textbackslash{}(@x); \newline Is equal to \newline @reflist=map(\textbackslash{}\$\_\}@x; \newline \newline @reflist = \textbackslash{}fx(); \newline Is equal to \newline @reflist=map\{\textbackslash{}\$\_\} fx(); \newline \newline @reflist=\textbackslash{}(fx(), fy(), fz()); \newline Is equal to \newline @reflist=map\{\textbackslash{}\$\_\} fx(), fy(), fz(); \newline \newline \newline @reflist=\textbackslash{}localtime(); \#ref to each of nine time elements \newline \$lastref = \textbackslash{}localtime() \#ref to whether it's daylight saving time} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{variable as a a variable name}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{\$\$ref is scalar value of \$ref refers to \newline @\$ref is array values of \$ref refers to \newline \%\$ref is hash values of \$ref referes to \newline \newline \$foo = "three humps"; \newline \$scalarref = \textbackslash{}\$foo; \newline \$camel\_model= \$\$scalarref; \newline \newline push(@\$arrayref, \$filename); \newline \newline \$\$arrayref{[}0{]}="Janualry" ; set the first element of @\$arrayref; \newline @\$arrayref{[}4…6{]} = qw /may June July/; \newline \newline \%\$hashref = (KEY=\textgreater{}"RING", BIRD=\textgreater{}"Sing") \newline \$\$hashref\{KEY\}="VALUE"; \newline \newline @\$hashref\{"KEY1", "KEY2"\}=("VAL1", "VAL2"); \newline \newline \$refrefref=\textbackslash{}\textbackslash{}\textbackslash{}"hody"; \newline print (\$\$\$\$refrefref);} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Sigil =\textgreater{} \$ (dollar means sigil)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Hashes}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{my \%map=("aa", 1, "bb", 2); \newline or \newline my \%map=(aa=\textgreater{}1, bb=\textgreater{}2,); \newline or \newline \$map\{aa\}=1; \newline \$map\{bb\}=2; \newline Reference: \newline \$map=\{ "aa". =\textgreater{} 1, "bb"=\textgreater{}2 \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Dereference: \newline \%m=\%\$map; \newline print(\$m\{aa\}); \newline Or \newline print(\$map-\textgreater{}\{aa\});} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Type glob and file handles}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{*foo contains values of \$foo, @foo, \%foo, \$foo, \newline % Row Count 1 (+ 1) Typeglob stores entire symbol table entry \newline % Row Count 2 (+ 1) {\emph{foo=}}bar; \newline % Row Count 3 (+ 1) It makes everything named foo. synonymous to every corresponding thing name bar \newline % Row Count 5 (+ 2) *foo=\textbackslash{}\$bar; \newline % Row Count 6 (+ 1) Makes an foo an alias of bar but doesn't make it for @foo an alias for @bar.% Row Count 8 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Backtic operator}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{\$perl\_info=qx(ps \$\$); \#thats perl% Row Count 1 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{\$k = `ls`; Interpreted in shell and store the result in \$k \newline \$shell\_info=qx'ps. \$\$'; \#thats shell} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Line Input Operator}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{While(\$\_=defined(\textless{}STDIN\textgreater{}))\{ \newline % Row Count 1 (+ 1) print \} or \newline % Row Count 2 (+ 1) print \$\_ while defined(\$\_=\textless{}STDIN\textgreater{}); \newline % Row Count 3 (+ 1) \$one\_line=\textless{}MYFILE\textgreater{} \newline % Row Count 4 (+ 1) @alllines=\textless{}MYFILE\textgreater{}% Row Count 5 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Filename Globbing operator}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{@files =\textless{}{\emph{.xml\textgreater{} \newline To \newline Filehandle in a variable \newline \textless{}\$foo\textgreater{} \newline \newline @files=glob(}}".xml"); \newline \newline while(glob {\emph{.c)\{ \newline chmod 0644 \$\_ \newline \} \newline @files=gob("\$dir/}}.{[}ch{]}");} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Statement}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Loop Control: \newline % Row Count 1 (+ 1) last, next, redo \newline % Row Count 2 (+ 1) LINE:while(\textless{}STDIN\textgreater{})\{ \newline % Row Count 3 (+ 1) last LINE if \textasciitilde{}/\textasciicircum{}\$/; \newline % Row Count 4 (+ 1) eval \{ \}; print (\$@) \#captures error \newline % Row Count 5 (+ 1) Scoped variables :% Row Count 6 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Named Unary operators}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{3.833cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/sathyanarayanan_1623845520_Picture1.jpg}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{To declare and define named sub routine}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Sub Name Block \newline % Row Count 2 (+ 2) Sub Name Proto Block \newline % Row Count 4 (+ 2) Sub Name Proto attr Block% Row Count 5 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Subroutines without names: \newline save return values at compile time, but also returns value \newline \$subref = sub Block;} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{To import subroutines}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{use MODULE qw(Name1 Name2 Name3)% Row Count 1 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.6866 cm} x{2.7464 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{call subroutine}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{Name(LIST)} & \& is optional with parameter or Name LIST \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Name & exposes current @\_ to that subroutine \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Indirect call}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{\&\$subref(LIST ) \newline % Row Count 1 (+ 1) \&\$subref-\textgreater{}(LIST), \newline % Row Count 2 (+ 1) \&\$subref% Row Count 3 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Semantics}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Sub razzle\{ \newline print "Ok" \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Default parameter @\_; \newline Which is local array \newline \$\_{[}0{]}., \$\_{[}1{]} are the first two elements of array} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Inline constant function}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{sub FLAG\_FOO () \{ 1 \textless{}\textless{} 8 \} \newline sub FLAG\_BAR () \{ 1 \textless{}\textless{} 9 \} \newline sub FLAG\_MASK () \{ FLAG\_FOO | FLAG\_BAR \} \newline \newline sub OPT\_GLARCH()\{ \newline \{ (0x1B58 \& FLAG\_MASK) == 0 \} \{ \newline \{ return 23 \} \newline \{ return 42 \} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{To return hash memory}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Sub hashem\{ +\{@\_\} \} \newline Sub hashem\{ return\{@\_\}\}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Anonymous subroutine composer \newline \newline \$coderef = sub \{print "Boink!\textbackslash{}n"\}; \newline \newline Semicolon is to terminate \$coderef; \newline Sub \{ \} \textgreater{} code inside is not executed immediately, it just generates reference to code.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{References}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{References are like \& in C \newline % Row Count 1 (+ 1) Anonymous hash with braces \newline % Row Count 2 (+ 1) \$hashref=\{ \newline % Row Count 3 (+ 1) "adam" =\textgreater{} "eve", \newline % Row Count 4 (+ 1) "clde"=\textgreater{}\$bonnie \newline % Row Count 5 (+ 1) \}% Row Count 6 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Hash of array}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{\%table= ( \newline 'john' =\textgreater{}{[}47, 'brown',186{]}, \newline 'mary '=\textgreater{}{[}23, 'hazel', 128{]} \newline ); \newline \newline print @\{\$table\{john\}\}{[}0{]};} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{prints 47} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}