|
5 | 5 | }, |
6 | 6 | "if statement": { |
7 | 7 | "prefix":"if", |
8 | | -"body": ["if ( ${1:condition} ) {","\t${0:body}","}"] |
| 8 | +"body": ["if ( ${1:condition} ) {","\t${2:body}","}"] |
9 | 9 | }, |
10 | 10 | "if else statement": { |
11 | 11 | "prefix":"ife", |
12 | 12 | "body": [ |
13 | 13 | "if ( ${1:condition} ) {", |
14 | 14 | "\t${2:body}", |
15 | 15 | "} else {", |
16 | | -"\t${0:body}", |
| 16 | +"\t${3:body}", |
17 | 17 | "}" |
18 | 18 | ] |
19 | 19 | }, |
|
23 | 23 | "if ( ${1:condition} ) {", |
24 | 24 | "\t${2:body}", |
25 | 25 | "} elsif ( ${3:condition} ) {", |
26 | | -"\t${0:body}", |
| 26 | +"\t${3:body}", |
27 | 27 | "}" |
28 | 28 | ] |
29 | 29 | }, |
30 | 30 | "else statement": { |
31 | 31 | "prefix":"else", |
32 | | -"body": ["else {","\t${0:body}","}"] |
| 32 | +"body": ["else {","\t${1:body}","}"] |
33 | 33 | }, |
34 | 34 | "elsif statement": { |
35 | 35 | "prefix":"elsif", |
36 | | -"body": ["elsif ( ${1:condition} ) {","\t${0:body}","}"] |
| 36 | +"body": ["elsif ( ${1:condition} ) {","\t${2:body}","}"] |
37 | 37 | }, |
38 | 38 | "unless": { |
39 | 39 | "prefix":"unless", |
40 | | -"body": ["unless ( ${1:condition} ) {","\t${0:body}","}"] |
| 40 | +"body": ["unless ( ${1:condition} ) {","\t${2:body}","}"] |
41 | 41 | }, |
42 | 42 | "for loop": { |
43 | 43 | "prefix":"for", |
44 | 44 | "body": [ |
45 | | -"for (my $${1:loop var} = 0; $$1 < ${2:count}; $$1++) {", |
46 | | -"\t${0:body}", |
| 45 | +"for (my\\$${1:loop var} = 0;\\$$1 < ${2:count};\\$$1++) {", |
| 46 | +"\t${3:body}", |
47 | 47 | "}" |
48 | 48 | ] |
49 | 49 | }, |
50 | 50 | "foreach loop": { |
51 | 51 | "prefix":"foreach", |
52 | | -"body": ["foreach my $${1:element} ( @${2:array} ) {","\t${0:body}","}"] |
| 52 | +"body": ["foreach my\\$${1:element} ( @${2:array} ) {","\t${3:body}","}"] |
53 | 53 | }, |
54 | 54 | "while Loop": { |
55 | 55 | "prefix":"while", |
56 | | -"body": ["while ( ${1:condition} ) {","\t${0:body}","}"] |
| 56 | +"body": ["while ( ${1:condition} ) {","\t${2:body}","}"] |
57 | 57 | }, |
58 | 58 | "do while Loop": { |
59 | 59 | "prefix":"dowhile", |
60 | | -"body": ["do {","\t${0:body}","} while ( ${1:condition} );"] |
| 60 | +"body": ["do {","\t${2:body}","} while ( ${1:condition} );"] |
61 | 61 | }, |
62 | 62 | "subroutine": { |
63 | 63 | "prefix":"sub", |
64 | | -"body": ["sub ${1:subroutine name} {","\t${0:subbody}","}"] |
| 64 | +"body": ["sub ${1:sub_name} {","\t${2:body}","}"] |
65 | 65 | }, |
66 | 66 | "Comment block for subroutine": { |
67 | | -"prefix":"#subdocumentation", |
| 67 | +"prefix":"documentation", |
68 | 68 | "body": [ |
69 | 69 | "################################################################################", |
70 | 70 | "#", |
|
81 | 81 | "open file to read": { |
82 | 82 | "prefix":"openr", |
83 | 83 | "body": [ |
84 | | -"open(my $${1:fh}, '<',\"${2:file name}\") or die\"Cannot open file '$2' for reading: $!\";" |
| 84 | +"open(my\\$${1:fh}, '<',\"${2:file name}\") or die\"Cannot open file '$2' for reading:\\$!\";" |
85 | 85 | ] |
86 | 86 | }, |
87 | 87 | "open file to write": { |
88 | 88 | "prefix":"openw", |
89 | 89 | "body": [ |
90 | | -"open(my $${1:fh}, '>',\"${2:file name}\") or die\"Cannot open file '$2' for writing: $!\";" |
| 90 | +"open(my\\$${1:fh}, '>',\"${2:file name}\") or die\"Cannot open file '$2' for writing:\\$!\";" |
91 | 91 | ] |
92 | 92 | }, |
93 | 93 | "print to file": { |
94 | 94 | "prefix":"file print", |
95 | | -"body": ["print${1:fh}\"$2\\n\";"] |
| 95 | +"body": ["print\\$${1:fh}\"${1:string}\\n\";"] |
96 | 96 | }, |
97 | 97 | "read file into a scalar": { |
98 | 98 | "prefix":"slurp", |
99 | 99 | "body": [ |
100 | | -"local $/;", |
101 | | -"open(my $${1:fh}, '<',\"${2:file name}\") or die\"Cannot open file '$2' for reading: $!\";", |
102 | | -"my $${3:contents} = <$$1>;", |
103 | | -"close($$1);" |
| 100 | +"use File::Slurp;", |
| 101 | +"", |
| 102 | +"my\\$${1:contents} = read_file(\"${2:file_path}\")" |
104 | 103 | ] |
105 | 104 | }, |
106 | 105 | "read a directory": { |
107 | 106 | "prefix":"readdir", |
108 | 107 | "body": [ |
109 | | -"opendir(my$$dir, '$1') or die\"Cannot open directory '$1': $!\";", |
110 | | -"my @files = readdir($$dir);", |
111 | | -"closedir($$dir);" |
| 108 | +"opendir(my\\$${1:dir}, '$2') or die\"Cannot open directory '$2':\\$!\";", |
| 109 | +"my @files = readdir(\\$$1);", |
| 110 | +"closedir(\\$$1);" |
112 | 111 | ] |
113 | 112 | }, |
114 | 113 | "create a directory": { |
115 | 114 | "prefix":"mkdir", |
116 | | -"body": ["mkdir\"${1:dir}\" or die\"Cannot create directory '$1': $!\";"] |
| 115 | +"body": [ |
| 116 | +"mkdir\"${1:dir}\" or die\"Cannot create directory '$1':\\$!\";" |
| 117 | + ] |
117 | 118 | }, |
118 | 119 | "split a string": { |
119 | 120 | "prefix":"split", |
|
124 | 125 | "join array": { |
125 | 126 | "prefix":"join", |
126 | 127 | "body": [ |
127 | | -"my $${1:string var} = join('${2:delimiter pattern}', @${3:array var});" |
| 128 | +"my\\$${1:string var} = join('${2:delimiter pattern}', @${3:array_var});" |
128 | 129 | ] |
129 | 130 | }, |
130 | 131 | "format time": { |
|
138 | 139 | "prefix":"trycatch", |
139 | 140 | "body": [ |
140 | 141 | "use Try::Tiny;", |
| 142 | +"", |
141 | 143 | "try {", |
142 | | -"\t${0:body}", |
| 144 | +"\t${1:body}", |
143 | 145 | "} catch {", |
144 | | -"\tmy $${1:err} = shift;", |
145 | | -"\tprint\"Error: $$1\\n\";", |
| 146 | +"\tmy\\$catch_error = shift;", |
| 147 | +"\tprint\"Error:\\$catch_error\\n\";", |
| 148 | +"} finally {", |
| 149 | +"\tif (@_) {", |
| 150 | +"\t\tprint\"The try block died with error: @_\\n\"", |
| 151 | +"\t} else {", |
| 152 | +"\t\tprint\"The try ran successfully.\\n\"", |
| 153 | +"\t}", |
146 | 154 | "};" |
147 | 155 | ] |
148 | 156 | }, |
149 | 157 | "perl module": { |
150 | | -"prefix":"perlmod", |
| 158 | +"prefix":"module package", |
151 | 159 | "body": [ |
152 | 160 | "package ${1:ModuleName};", |
153 | 161 | "use strict;", |
154 | 162 | "use warnings;", |
155 | 163 | "", |
156 | 164 | "sub new {", |
157 | | -"\tmy ($$class, %args) = @_;", |
158 | | -"\tmy$$self = bless {%args},$$class;", |
159 | | -"\treturn$$self;", |
| 165 | +"\tmy (\\$class, %args) = @_;", |
| 166 | +"\tmy\\$self = bless {%args},\\$class;", |
| 167 | +"\treturn\\$self;", |
160 | 168 | "}", |
161 | 169 | "", |
162 | 170 | "# Add more methods here", |
163 | | -"$0", |
| 171 | +"$2", |
164 | 172 | "", |
165 | 173 | "1; # Return true to indicate successful module loading" |
166 | 174 | ] |
|