-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
polish.sbv
418 lines (271 loc) · 7.15 KB
/
polish.sbv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
0:00:04.029,0:00:08.730
Cześć, witam ponownie na moim kanale.
Tym razem pokażę,
jak używać wbudowanego
0:00:08.730,0:00:10.989
debuggera perla
0:00:10.989,0:00:12.389
jako REPLa (pętla wczytaj-wykonaj-wypisz).
0:00:12.389,0:00:15.339
Nie będziemy debugować
żadnego skryptu
0:00:15.339,0:00:19.559
zamiast tego będziemy zgłębiać
tajniki działania perla.
0:00:19.559,0:00:22.019
Zatem otwieramy wiersz poleceń
0:00:22.019,0:00:24.060
Jak wiecie, możemy wpisać
perl -e
0:00:24.060,0:00:28.079
a następnie jakiś kod perla.
perl -e 'print 42'
0:00:28.079,0:00:31.939
Po wykonaniu widzimy,
że zostało wypisane 42.
0:00:31.939,0:00:35.380
Równie dobrze możemy jako wartość
podać jedynkę
0:00:35.380,0:00:37.040
perl -e 1
0:00:37.040,0:00:40.660
czyli po prostu pusty skrypt.
Wykonujemy polecenie
0:00:40.660,0:00:41.770
i nic się nie dzieje.
0:00:41.770,0:00:45.090
Teraz, dodając -d, możemy włączyć debugger
0:00:45.090,0:00:47.120
perl -d -e 1
0:00:47.120,0:00:52.770
Ale ponieważ w wierszu poleceń możemy
łączyć opcje
0:00:52.770,0:00:57.420
wpiszemy po prostu:
perl -de1
0:00:57.420,0:00:58.750
Po wykonaniu tej komendy
0:00:58.750,0:01:04.360
debugger wykonuje pusty skrypt
0:01:04.360,0:01:05.540
a następnie wyświetla linię poleceń.
0:01:05.540,0:01:10.080
Możemy teraz wpisać dowolne polecenie perla.
0:01:10.080,0:01:12.299
Więc na przykład wpiszę
print 42
0:01:12.299,0:01:16.230
i liczba 42 została wypisana.
0:01:16.230,0:01:19.920
Mogę także wpisać
$x=42
0:01:19.920,0:01:23.940
przypisując zmiennej $x$
wartość 42.
0:01:23.940,0:01:24.910
Możemy teraz użyć
0:01:24.910,0:01:30.660
funkcji print do wypisania tej zmiennej
lub użyć wbudowanego narzędzia
0:01:30.660,0:01:31.830
debuggera, którym jest
0:01:31.830,0:01:36.040
polecenie p, do jej wypisania.
0:01:36.040,0:01:38.950
Analogicznie jak przy przypisywaniu
wartości możemy stworzyć tablicę.
0:01:38.950,0:01:42.350
Na przykład:
0:01:42.350,0:01:47.210
tablica imion
0:01:47.210,0:01:48.900
Foo Bar i Baz
@names=qw(Foo Bar Baz)
0:01:48.900,0:01:52.740
możemy teraz wypisać imiona
0:01:52.740,0:01:54.540
zwyczajnym poleceniem print
print @names
0:01:54.540,0:01:57.550
Oczywiście wynik nie wygląda
zbyt dobrze.
0:01:57.550,0:01:58.520
Możemy jednak nazwę tablicy
0:01:58.520,0:02:00.659
wziąć w cudzysłów:
print "@names"
0:02:00.659,0:02:04.420
Wygląda teraz nieco lepiej,
ponieważ imiona oddzielone są spacjami
0:02:04.420,0:02:08.569
jednak wypisując tablicę w ten sposób
nie jesteśmy do końca pewni,
0:02:08.569,0:02:14.869
czy tablica zawiera trzy różne wartości,
czy pojedynczą wartość ze spacjami wewnątrz.
0:02:14.869,0:02:18.290
Zatem lepszym sposobem
wypisania zawartości tablicy
0:02:18.290,0:02:20.489
jest użycie wbudowanego
0:02:20.489,0:02:22.309
polecenia x
0:02:22.309,0:02:24.159
x \@names
0:02:24.159,0:02:28.579
i podanie mu referencji do tablicy.
Wówczas debugger wypisze,
0:02:28.579,0:02:32.429
że jest to referencja oraz
wypisze indeksy i wartości.
0:02:32.429,0:02:36.439
W podobny sposób
możemy stworzyć hash
0:02:36.439,0:02:44.799
piszemy więc
%h=(fname => 'Foo', lname => 'Bar')
0:02:44.799,0:02:45.949
0:02:45.949,0:02:49.089
0:02:49.089,0:02:53.709
W ten sposób stworzyliśmy hash.
0:02:53.709,0:02:56.250
Możemy go teraz wypisać
0:02:56.250,0:02:58.319
po raz kolejny używając polecenia x.
0:02:58.319,0:03:00.059
Znów wypisze ono informację,
że mamy do czynienia z referencją
0:03:00.059,0:03:04.649
oraz klucze i wartości.
0:03:04.649,0:03:05.629
0:03:05.629,0:03:06.859
0:03:06.859,0:03:09.170
Możemy robić także inne rzeczy
0:03:09.170,0:03:10.419
na przykład
0:03:10.419,0:03:13.159
dowiedzieć się jak działa
0:03:13.159,0:03:16.029
funkcja push.
0:03:16.029,0:03:20.669
Wpiszmy
push @names, 'Moose'
0:03:20.669,0:03:23.479
wracamy teraz do polecenia
x \@names
0:03:23.479,0:03:27.659
by wypisać zawartość tablicy.
Widzimy, że tablica
0:03:27.659,0:03:31.079
wydłużyła się
0:03:31.079,0:03:34.759
i teraz znajduje się w niej wartość 'Moose'.
0:03:34.759,0:03:38.729
Możemy więc badać kod perla
0:03:38.729,0:03:42.869
używając zarówno komend języka
0:03:42.869,0:03:44.270
jak i komend debuggera
0:03:44.270,0:03:47.089
jak na przykład print i x.
0:03:47.089,0:03:51.399
Możemy także używać modułów
0:03:51.399,0:03:52.319
na przykład wpisanie
use Cwd
0:03:52.319,0:03:55.040
spowoduje załadowanie modułu
0:03:55.040,0:03:58.969
ze wszystkimi zawartymi w nim funkcjami.
Możemy teraz wywołać zawartą w nim
0:03:58.969,0:04:00.810
funkcję cwd.
0:04:00.810,0:04:03.109
Oczywiście wywołanie jej
0:04:03.109,0:04:06.259
nie spowoduje wyświetlenia niczego,
ponieważ wywołanie zwraca wartość.
0:04:06.259,0:04:09.549
Jeśli zatem chcemy zobaczyć wynik tego polecenia
musimy napisać 'p cwd'.
0:04:09.549,0:04:14.909
Polecenie to wypisze wynik funkcji,
którym w tym przypadku jest nazwa katalogu roboczego.
0:04:14.909,0:04:16.920
Możemy też użyć innego modułu
0:04:16.920,0:04:20.069
na przykład basename
0:04:20.069,0:04:24.150
'use File::Basename'
0:04:24.150,0:04:29.889
oraz zawartej w nim funkcji basename.
0:04:29.889,0:04:33.740
Wywołajmy 'p basename(cwd)' przekazując funkcji
basename wynik cwd
0:04:33.740,0:04:35.209
0:04:35.209,0:04:39.370
0:04:39.370,0:04:40.580
Wynikiem jest główna część ścieżki
0:04:40.580,0:04:45.530
0:04:45.530,0:04:47.090
czyli po prostu jej ostatni człon.
0:04:47.090,0:04:50.299
0:04:50.299,0:04:54.259
Jeśli teraz chcielibyśmy się dowiedzieć
jak działa ta funkcja
0:04:54.259,0:04:55.099
0:04:55.099,0:04:56.330
możemy wstawić breakpoint.
0:04:56.330,0:04:59.909
0:04:59.909,0:05:02.059
'b File::Basename::basename'
0:05:02.059,0:05:03.449
0:05:03.449,0:05:04.620
0:05:04.620,0:05:09.019
Jeśli teraz uruchomię ten kod ponownie
0:05:09.019,0:05:11.050
0:05:11.050,0:05:13.169
zatrzyma się w punkcie, w którym wywołujemy
0:05:13.169,0:05:14.840
0:05:14.840,0:05:18.919
funkcję basename
0:05:18.919,0:05:20.169
'File::Basename::basename(C:/Strawberry/perl/lib/File/Basename.pm:215):'
0:05:20.169,0:05:25.050
zaimplementowaną w tym pliku, w linii 215.
0:05:25.050,0:05:26.740
Możemy zobaczyć kod przy pomocy 'l'
0:05:26.740,0:05:32.889
istnieje możliwość wyświetlenia całego kodu,
lub tylko wybranych linii:
0:05:32.889,0:05:35.910
'l 200-220'
0:05:35.910,0:05:37.789
0:05:37.789,0:05:39.830
Widzimy tutaj
0:05:39.830,0:05:41.590
kilka linii,
0:05:41.590,0:05:43.020
które prawdopodobnie nie są powiązane z naszą funkcją,
0:05:43.020,0:05:47.719
więc nie zostały wyświetlone,
a następnie funkcję basename
0:05:47.719,0:05:49.229
oraz opis jej działania.
0:05:49.229,0:05:51.849
Możesz zatem używać
0:05:51.849,0:05:53.899
dowolnego narzędzia debuggera
0:05:53.899,0:05:57.569
i w ten sposób badać kod perla.
0:05:57.569,0:05:59.409
Na zakończenie wpisujemy 'q'
0:05:59.409,0:06:01.330
by zakończyć działanie debuggera.
0:06:01.330,0:06:03.059
Mam nadzieję, że podobał wam się ten tutorial
0:06:03.059,0:06:04.680
i zapraszam do zasubskrybowania kanału.
0:06:04.680,0:06:08.460
Do zobaczenia!
0:06:08.460,0:06:09.280