| 1 | # #!/usr/bin/perl |
| 2 | snippet #! |
| 3 | #!/usr/bin/perl |
| 4 | |
| 5 | # Hash Pointer |
| 6 | snippet . |
| 7 | => |
| 8 | # Function |
| 9 | snippet sub |
| 10 | sub ${1:function_name} { |
| 11 | ${2:#body ...} |
| 12 | } |
| 13 | # Conditional |
| 14 | snippet if |
| 15 | if (${1}) { |
| 16 | ${2:# body...} |
| 17 | } |
| 18 | # Conditional if..else |
| 19 | snippet ife |
| 20 | if (${1}) { |
| 21 | ${2:# body...} |
| 22 | } |
| 23 | else { |
| 24 | ${3:# else...} |
| 25 | } |
| 26 | # Conditional if..elsif..else |
| 27 | snippet ifee |
| 28 | if (${1}) { |
| 29 | ${2:# body...} |
| 30 | } |
| 31 | elsif (${3}) { |
| 32 | ${4:# elsif...} |
| 33 | } |
| 34 | else { |
| 35 | ${5:# else...} |
| 36 | } |
| 37 | # Conditional One-line |
| 38 | snippet xif |
| 39 | ${1:expression} if ${2:condition};${3} |
| 40 | # Unless conditional |
| 41 | snippet unless |
| 42 | unless (${1}) { |
| 43 | ${2:# body...} |
| 44 | } |
| 45 | # Unless conditional One-line |
| 46 | snippet xunless |
| 47 | ${1:expression} unless ${2:condition};${3} |
| 48 | # Try/Except |
| 49 | snippet eval |
| 50 | eval { |
| 51 | ${1:# do something risky...} |
| 52 | }; |
| 53 | if ($@) { |
| 54 | ${2:# handle failure...} |
| 55 | } |
| 56 | # While Loop |
| 57 | snippet wh |
| 58 | while (${1}) { |
| 59 | ${2:# body...} |
| 60 | } |
| 61 | # While Loop One-line |
| 62 | snippet xwh |
| 63 | ${1:expression} while ${2:condition};${3} |
| 64 | # C-style For Loop |
| 65 | snippet cfor |
| 66 | for (my $${2:var} = 0; $$2 < ${1:count}; $$2${3:++}) { |
| 67 | ${4:# body...} |
| 68 | } |
| 69 | # For loop one-line |
| 70 | snippet xfor |
| 71 | ${1:expression} for @${2:array};${3} |
| 72 | # Foreach Loop |
| 73 | snippet for |
| 74 | foreach my $${1:x} (@${2:array}) { |
| 75 | ${3:# body...} |
| 76 | } |
| 77 | # Foreach Loop One-line |
| 78 | snippet fore |
| 79 | ${1:expression} foreach @${2:array};${3} |
| 80 | # Package |
| 81 | snippet cl |
| 82 | package ${1:ClassName}; |
| 83 | |
| 84 | use base qw(${2:ParentClass}); |
| 85 | |
| 86 | sub new { |
| 87 | my $class = shift; |
| 88 | $class = ref $class if ref $class; |
| 89 | my $self = bless {}, $class; |
| 90 | $self; |
| 91 | } |
| 92 | |
| 93 | 1;${3} |
| 94 | # Read File |
| 95 | snippet slurp |
| 96 | my $${1:var}; |
| 97 | { local $/ = undef; local *FILE; open FILE, "<${2:file}"; $$1 = <FILE>; close FILE }${3} |