Perl 5 version 32.0 documentation

perlcheat

NAME

perlcheat - Perl 5 Cheat Sheet

DESCRIPTION

This 'cheat sheet' is a handy reference, meant for beginning Perl programmers. Not everything is mentioned, but 195 features may already be overwhelming.

The sheet

  1. CONTEXTS SIGILS ref ARRAYS HASHES
  2. void $scalar SCALAR @array %hash
  3. scalar @array ARRAY @array[0, 2] @hash{'a', 'b'}
  4. list %hash HASH $array[0] $hash{'a'}
  5. &sub CODE
  6. *glob GLOB SCALAR VALUES
  7. FORMAT number, string, ref, glob, undef
  8. REFERENCES
  9. \ reference $$foo[1] aka $foo->[1]
  10. $@%&* dereference $$foo{bar} aka $foo->{bar}
  11. [] anon. arrayref ${$$foo[1]}[2] aka $foo->[1]->[2]
  12. {} anon. hashref ${$$foo[1]}[2] aka $foo->[1][2]
  13. \() list of refs
  14. SYNTAX
  15. OPERATOR PRECEDENCE foreach (LIST) { } for (a;b;c) { }
  16. -> while (e) { } until (e) { }
  17. ++ -- if (e) { } elsif (e) { } else { }
  18. ** unless (e) { } elsif (e) { } else { }
  19. ! ~ \ u+ u- given (e) { when (e) {} default {} }
  20. =~ !~
  21. * / % x NUMBERS vs STRINGS FALSE vs TRUE
  22. + - . = = undef, "", 0, "0"
  23. << >> + . anything else
  24. named uops == != eq ne
  25. < > <= >= lt gt le ge < > <= >= lt gt le ge
  26. == != <=> eq ne cmp ~~ <=> cmp
  27. &
  28. | ^ REGEX MODIFIERS REGEX METACHARS
  29. && /i case insensitive ^ string begin
  30. || // /m line based ^$ $ str end (bfr \n)
  31. .. ... /s . includes \n + one or more
  32. ?: /x /xx ign. wh.space * zero or more
  33. = += last goto /p preserve ? zero or one
  34. , => /a ASCII /aa safe {3,7} repeat in range
  35. list ops /l locale /d dual | alternation
  36. not /u Unicode [] character class
  37. and /e evaluate /ee rpts \b boundary
  38. or xor /g global \z string end
  39. /o compile pat once () capture
  40. DEBUG (?:p) no capture
  41. -MO=Deparse REGEX CHARCLASSES (?#t) comment
  42. -MO=Terse . [^\n] (?=p) ZW pos ahead
  43. -D## \s whitespace (?!p) ZW neg ahead
  44. -d:Trace \w word chars (?<=p) ZW pos behind \K
  45. \d digits (?<!p) ZW neg behind
  46. CONFIGURATION \pP named property (?>p) no backtrack
  47. perl -V:ivsize \h horiz.wh.space (?|p|p)branch reset
  48. \R linebreak (?<n>p)named capture
  49. \S \W \D \H negate \g{n} ref to named cap
  50. \K keep left part
  51. FUNCTION RETURN LISTS
  52. stat localtime caller SPECIAL VARIABLES
  53. 0 dev 0 second 0 package $_ default variable
  54. 1 ino 1 minute 1 filename $0 program name
  55. 2 mode 2 hour 2 line $/ input separator
  56. 3 nlink 3 day 3 subroutine $\ output separator
  57. 4 uid 4 month-1 4 hasargs $| autoflush
  58. 5 gid 5 year-1900 5 wantarray $! sys/libcall error
  59. 6 rdev 6 weekday 6 evaltext $@ eval error
  60. 7 size 7 yearday 7 is_require $$ process ID
  61. 8 atime 8 is_dst 8 hints $. line number
  62. 9 mtime 9 bitmask @ARGV command line args
  63. 10 ctime 10 hinthash @INC include paths
  64. 11 blksz 3..10 only @_ subroutine args
  65. 12 blcks with EXPR %ENV environment

ACKNOWLEDGEMENTS

The first version of this document appeared on Perl Monks, where several people had useful suggestions. Thank you, Perl Monks.

A special thanks to Damian Conway, who didn't only suggest important changes, but also took the time to count the number of listed features and make a Raku version to show that Perl will stay Perl.

AUTHOR

Juerd Waalboer <#####@juerd.nl>, with the help of many Perl Monks.

SEE ALSO