ANONYMOUS ARRAYS Here's a little prep for our array handling. Scalers can not be set equal to arrays. $v1 = ("one", "two"); # BAD But you can set a scaler to a reference to an "anonymous" array. (Anonymous arrays are delimited with []. Not to be confused with subscripts, which also happen to be delimited with [].) $v1 = ["one", "two"]; # GOOD But remember that $v1 is not an array but a reference to an anonymous array. Therefore, to access an element of one of the given arrays, we need something like $$v1[1] (not just $v1[1]!). In our program, we are setting hash values to references to anonymous arrays. So, similarly to above, we must do extra dereferencing when using the data. Here are examples of the critically important uses. print "${$hash{key}}[1]\n"; # An individual array element (index of 1) print $#{$hash{key}}; # Size (-1) of array referenced by $hash{key} @array = @{$hash{key}}; # Make anony array into a direct array Escape characters. Binary. Unicode. \007 Any octal \x7f Any hex \N{LATIN CAPITAL LETTER A} See file "doc/tech/re.txt" about Regular Expressions. Referencing @newVar apparently allocates value (), since: @newVar = (); is unnecessary and apparently useless. Unless strict mode active, can just: push @newVar, 9; or print "$#newVar\n"; Tests (@array) and (%hash) apparently test for size != -1. Funky but works. Be aware of wacky requirements for usage of barewords. Good: print STDERR (anything); BAD: print STDERR(anything); New way of installing packages: One time install as root: Download script "cpanm". cpanm App::cpanminus # n.b. typo on "How to install.." page Thereafter, use cpanm -l installation/root New:Module Traditional way to install a package/module: Most graceful way to add a lib directory to a perl script: use lib '/path/to/lib/dir'; Slurping input Undef $/ manually or with -0 switch. I can't get -0FFF or -00FFF to work, but -0 with nothing after it works. With -n/-p: #!/usr/bin/perl -wn0 OR BEGIN { undef $/; } ... print "($_)"; Without: #!/usr/bin/perl -w0 $_ = <>; print "($_)"; Invocation In-place editing with backup. DOESN'T WORK ON WINDOWS! perl -[np]wi.orig -e '...' files... Unicode Looks like \u... is specific to Java and JavaScript. For 2-byte codes use hex like \x12. Use this before write to stdout: binmode STDOUT ":utf8"; 4-byte, I don't know. Base system does not include a list uniquifier function, but this works: (Input array @ar; output array @unique). my @unique = do { my %seen; grep { !$seen{$_}++ } @ar }; For some reason the perl bundled in Gitforwindows sets default value for -i switch. If you give just 'perl -i ...', it's as if you run 'perl -i.bak ...' Very common use case is to parse something out of some input and exit with true only if it is able to do so. perl -nwe 'use vars qw/$xv/; if (/x(.+)/) { $xv=0; print "$1\n"; exit; }; END { exit $xv; } BEGIN { $xv = 1; }' More nicely formatted ("code-templates/simpleParse.pl"): perl -nwe ' use vars qw/$xv/; if (/"Value": *"([^"]+)/) { $xv=0; print "$1\n"; exit; } END { exit $xv; } BEGIN { $xv = 1; } ' -na / -pa / -Fpattern switches for automatic tokenizing input into @F. -F sets the input delimiter pattern but also implicitly set -a and -n. AWESOME: For most use cases, simply use: perl -Fx -e ˙...' pretty-printing / dumping hashes and lists: Neither hashes nor lists can be displayed directly. List can be displayed easily just by using join: print(join(":", @list)); Hashes require Data::Dumper module: use Data::Dumper; $Data::Dumper::Varname=""; $Data::Dumper::Indent=0; print(Dumper(\%h)); Typical simple dumping: print Dumper(\%hashname); strings: Variable expansion is like Bourne, where "$x" expands but '$x' does not. But different from Bourne: Char escapes work only with ": "helo\n" works but 'helo\n' does not. Perl has no trim function for some damned reason. Must use: $x =~ s/^\s+/; $x =~ s/\s+$//; OR on $_: s/^\s+/; s/\s+$//; Multi-line: HERE documents: ... = << ' END_MESSAGE'; ** ' or " drives interp behavior. " does interp .... END_MESSAGE OR q/qq: ... = qq@ q or qq drives inter behavior. qq does interp ... @ With both methods you must post-process to change the coded indentations and/or prefix/suffix. OPERATORS Remember when comparing strings to use the string operators like 'eq', 'ne' instead of ==, !=. NEW FEATURES https://stackoverflow.blog/2022/09/08/this-is-not-your-grandfathers-perl/?utm_source=Iterable&utm_medium=email&utm_campaign=the_overflow_newsletter chop vs. chomp: chop simply removes the final character and is much more efficient chomp removes all trailing $/ sequences, if any. Length of an array: scalar @arr $scal = @arr // same but implicitly $#arr // == length-1 DOES NOT WORK: "length is @arr\n" DOES NOT WORK: "length is $@arr\n"