Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit637d90e

Browse files
authored
Snippets for Perl language (rafamadriz#450)
1 parentd061007 commit637d90e

File tree

1 file changed

+168
-0
lines changed

1 file changed

+168
-0
lines changed

‎snippets/perl.json‎

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
{
2+
"print statement": {
3+
"prefix":"print",
4+
"body": ["print\"$1\\n\";"]
5+
},
6+
"if statement": {
7+
"prefix":"if",
8+
"body": ["if ( ${1:condition} ) {","\t${0:body}","}"]
9+
},
10+
"if else statement": {
11+
"prefix":"ife",
12+
"body": [
13+
"if ( ${1:condition} ) {",
14+
"\t${2:body}",
15+
"} else {",
16+
"\t${0:body}",
17+
"}"
18+
]
19+
},
20+
"if else if statement": {
21+
"prefix":"iffe",
22+
"body": [
23+
"if ( ${1:condition} ) {",
24+
"\t${2:body}",
25+
"} elsif ( ${3:condition} ) {",
26+
"\t${0:body}",
27+
"}"
28+
]
29+
},
30+
"else statement": {
31+
"prefix":"else",
32+
"body": ["else {","\t${0:body}","}"]
33+
},
34+
"elsif statement": {
35+
"prefix":"elsif",
36+
"body": ["elsif ( ${1:condition} ) {","\t${0:body}","}"]
37+
},
38+
"unless": {
39+
"prefix":"unless",
40+
"body": ["unless ( ${1:condition} ) {","\t${0:body}","}"]
41+
},
42+
"for loop": {
43+
"prefix":"for",
44+
"body": [
45+
"for (my $${1:loop var} = 0; $$1 < ${2:count}; $$1++) {",
46+
"\t${0:body}",
47+
"}"
48+
]
49+
},
50+
"foreach loop": {
51+
"prefix":"foreach",
52+
"body": ["foreach my $${1:element} ( @${2:array} ) {","\t${0:body}","}"]
53+
},
54+
"while Loop": {
55+
"prefix":"while",
56+
"body": ["while ( ${1:condition} ) {","\t${0:body}","}"]
57+
},
58+
"do while Loop": {
59+
"prefix":"dowhile",
60+
"body": ["do {","\t${0:body}","} while ( ${1:condition} );"]
61+
},
62+
"subroutine": {
63+
"prefix":"sub",
64+
"body": ["sub ${1:subroutine name} {","\t${0:sub body}","}"]
65+
},
66+
"Comment block for subroutine": {
67+
"prefix":"#sub documentation",
68+
"body": [
69+
"################################################################################",
70+
"#",
71+
"# Author: ${1:Author}",
72+
"# Date: ${CURRENT_MONTH}/${CURRENT_DATE}/${CURRENT_YEAR}",
73+
"# Description: ${2:Description}",
74+
"#",
75+
"# Arguments:",
76+
"# * ${3:argument_name} - ${4:description}",
77+
"#",
78+
"################################################################################"
79+
]
80+
},
81+
"open file to read": {
82+
"prefix":"openr",
83+
"body": [
84+
"open(my $${1:fh}, '<',\"${2:file name}\") or die\"Cannot open file '$2' for reading: $!\";"
85+
]
86+
},
87+
"open file to write": {
88+
"prefix":"openw",
89+
"body": [
90+
"open(my $${1:fh}, '>',\"${2:file name}\") or die\"Cannot open file '$2' for writing: $!\";"
91+
]
92+
},
93+
"print to file": {
94+
"prefix":"file print",
95+
"body": ["print ${1:fh}\"$2\\n\";"]
96+
},
97+
"read file into a scalar": {
98+
"prefix":"slurp",
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);"
104+
]
105+
},
106+
"read a directory": {
107+
"prefix":"readdir",
108+
"body": [
109+
"opendir(my $$dir, '$1') or die\"Cannot open directory '$1': $!\";",
110+
"my @files = readdir($$dir);",
111+
"closedir($$dir);"
112+
]
113+
},
114+
"create a directory": {
115+
"prefix":"mkdir",
116+
"body": ["mkdir\"${1:dir}\" or die\"Cannot create directory '$1': $!\";"]
117+
},
118+
"split a string": {
119+
"prefix":"split",
120+
"body": [
121+
"my @${1:array var} = split(/${2:delimiter pattern}/,\"${3:string}\");"
122+
]
123+
},
124+
"join array": {
125+
"prefix":"join",
126+
"body": [
127+
"my $${1:string var} = join('${2:delimiter pattern}', @${3:array var});"
128+
]
129+
},
130+
"format time": {
131+
"prefix":"strftime",
132+
"body": [
133+
"use POSIX qw(strftime);",
134+
"my $formatted = strftime('%Y-%m-%d %H:%M:%S', localtime($1));"
135+
]
136+
},
137+
"try catch block": {
138+
"prefix":"trycatch",
139+
"body": [
140+
"use Try::Tiny;",
141+
"try {",
142+
"\t${0:body}",
143+
"} catch {",
144+
"\tmy $${1:err} = shift;",
145+
"\tprint\"Error: $$1\\n\";",
146+
"};"
147+
]
148+
},
149+
"perl module": {
150+
"prefix":"perlmod",
151+
"body": [
152+
"package ${1:ModuleName};",
153+
"use strict;",
154+
"use warnings;",
155+
"",
156+
"sub new {",
157+
"\tmy ($$class, %args) = @_;",
158+
"\tmy $$self = bless {%args}, $$class;",
159+
"\treturn $$self;",
160+
"}",
161+
"",
162+
"# Add more methods here",
163+
"$0",
164+
"",
165+
"1; # Return true to indicate successful module loading"
166+
]
167+
}
168+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp