1 |
argrath |
1.1 |
|
2 |
|
|
=encoding euc-jp |
3 |
|
|
|
4 |
|
|
=head1 NAME |
5 |
|
|
|
6 |
|
|
=begin original |
7 |
|
|
|
8 |
|
|
perlfaq3 - Programming Tools |
9 |
|
|
|
10 |
|
|
=end original |
11 |
|
|
|
12 |
|
|
perlfaq3 - プログラミングツール |
13 |
|
|
|
14 |
|
|
=head1 DESCRIPTION |
15 |
|
|
|
16 |
|
|
=begin original |
17 |
|
|
|
18 |
|
|
This section of the FAQ answers questions related to programmer tools |
19 |
|
|
and programming support. |
20 |
|
|
|
21 |
|
|
=end original |
22 |
|
|
|
23 |
|
|
FAQ のこのセクションでは、プログラマーツールやプログラミングサポートに |
24 |
|
|
関する質問に回答しています。 |
25 |
|
|
|
26 |
|
|
=head2 How do I do (anything)? |
27 |
|
|
|
28 |
|
|
(○○をするにはどうすればいいの?) |
29 |
|
|
|
30 |
|
|
=begin original |
31 |
|
|
|
32 |
|
|
Have you looked at CPAN (see L<perlfaq2>)? The chances are that |
33 |
|
|
someone has already written a module that can solve your problem. |
34 |
|
|
Have you read the appropriate manpages? Here's a brief index: |
35 |
|
|
|
36 |
|
|
=end original |
37 |
|
|
|
38 |
|
|
CPAN (L<perlfaq2> を参照して下さい)はもう見ましたか? |
39 |
|
|
あなたの問題を解決してくれるような |
40 |
|
|
モジュールを誰かがすでに作っているのを見つけられるかもしれません。 |
41 |
|
|
適切なマニュアルページは見ましたか? |
42 |
|
|
簡単なインデックスを挙げておきます: |
43 |
|
|
|
44 |
|
|
=begin original |
45 |
|
|
|
46 |
|
|
Basics perldata, perlvar, perlsyn, perlop, perlsub |
47 |
|
|
Execution perlrun, perldebug |
48 |
|
|
Functions perlfunc |
49 |
|
|
Objects perlref, perlmod, perlobj, perltie |
50 |
|
|
Data Structures perlref, perllol, perldsc |
51 |
|
|
Modules perlmod, perlmodlib, perlsub |
52 |
|
|
Regexes perlre, perlfunc, perlop, perllocale |
53 |
|
|
Moving to perl5 perltrap, perl |
54 |
|
|
Linking w/C perlxstut, perlxs, perlcall, perlguts, perlembed |
55 |
|
|
Various http://www.cpan.org/misc/olddoc/FMTEYEWTK.tgz |
56 |
|
|
(not a man-page but still useful, a collection |
57 |
|
|
of various essays on Perl techniques) |
58 |
|
|
|
59 |
|
|
=end original |
60 |
|
|
|
61 |
|
|
基礎 perldata, perlvar, perlsyn, perlop, perlsub |
62 |
|
|
実行 perlrun, perldebug |
63 |
|
|
関数 perlfunc |
64 |
|
|
オブジェクト perlref, perlmod, perlobj, perltie |
65 |
|
|
データ構造 perlref, perllol, perldsc |
66 |
|
|
モジュール perlmod, perlmodlib, perlsub |
67 |
|
|
正規表現 perlre, perlfunc, perlop, perllocale |
68 |
|
|
perl5への移行 perltrap, perl |
69 |
|
|
Cとのリンク perlxstut, perlxs, perlcall, perlguts, perlembed |
70 |
|
|
その他 http://www.cpan.org/misc/olddoc/FMTEYEWTK.tgz |
71 |
|
|
(man-page ではありませんが有用な、Perl のテクニックに |
72 |
|
|
関するコラム集です) |
73 |
|
|
|
74 |
|
|
=begin original |
75 |
|
|
|
76 |
|
|
A crude table of contents for the Perl manpage set is found in L<perltoc>. |
77 |
|
|
|
78 |
|
|
=end original |
79 |
|
|
|
80 |
|
|
無加工の Perl のマニュアルページセットの目次の一覧が L<perltoc> にあります。 |
81 |
|
|
|
82 |
|
|
=head2 How can I use Perl interactively? |
83 |
|
|
|
84 |
|
|
(対話的に Perl を使うには?) |
85 |
|
|
|
86 |
|
|
=begin original |
87 |
|
|
|
88 |
|
|
The typical approach uses the Perl debugger, described in the |
89 |
|
|
C<perldebug(1)> manpage, on an "empty" program, like this: |
90 |
|
|
|
91 |
|
|
=end original |
92 |
|
|
|
93 |
|
|
典型的なやり方は、C<perldebug(1)> マニュアルページにあるような Perl |
94 |
|
|
デバッガを以下の例のように「空の」プログラムに対して使うことです: |
95 |
|
|
|
96 |
|
|
perl -de 42 |
97 |
|
|
|
98 |
|
|
=begin original |
99 |
|
|
|
100 |
|
|
Now just type in any legal Perl code, and it will be immediately |
101 |
|
|
evaluated. You can also examine the symbol table, get stack |
102 |
|
|
backtraces, check variable values, set breakpoints, and other |
103 |
|
|
operations typically found in symbolic debuggers. |
104 |
|
|
|
105 |
|
|
=end original |
106 |
|
|
|
107 |
|
|
これで、正しい Perl コードをタイプするだけで即座にそれが評価されます。 |
108 |
|
|
同様に、シンボルテーブルの検査やスタックのバックトレースを得ること、 |
109 |
|
|
変数の値の確認、ブレークポイントの設定、そしてシンボリックデバッガで |
110 |
|
|
行える典型的な操作が可能です。 |
111 |
|
|
|
112 |
|
|
=head2 Is there a Perl shell? |
113 |
|
|
|
114 |
|
|
(Perl シェルはありますか?) |
115 |
|
|
|
116 |
|
|
=begin original |
117 |
|
|
|
118 |
|
|
The C<psh> (Perl sh) is currently at version 1.8. The Perl Shell is a shell |
119 |
|
|
that combines the interactive nature of a Unix shell with the power of |
120 |
|
|
Perl. The goal is a full featured shell that behaves as expected for |
121 |
|
|
normal shell activity and uses Perl syntax and functionality for |
122 |
|
|
control-flow statements and other things. You can get C<psh> at |
123 |
|
|
http://sourceforge.net/projects/psh/ . |
124 |
|
|
|
125 |
|
|
=end original |
126 |
|
|
|
127 |
|
|
C<psh> (Perl sh) は現在バージョン 1.8 です。 |
128 |
|
|
Perl Shell は Unix シェルの対話性と Perl の力を融合したものです。 |
129 |
|
|
目標は通常のシェルのような機能および、フロー制御やその他のことに |
130 |
|
|
Perl の文法と機能を使う完全な機能を持ったシェルです。 |
131 |
|
|
C<psh> は http://www.focusresearch.com/gregor/psh/ で入手できます。 |
132 |
|
|
|
133 |
|
|
=begin original |
134 |
|
|
|
135 |
|
|
C<Zoidberg> is a similar project and provides a shell written in perl, |
136 |
|
|
configured in perl and operated in perl. It is intended as a login shell |
137 |
|
|
and development environment. It can be found at |
138 |
|
|
http://pardus-larus.student.utwente.nl/~pardus/projects/zoidberg/ |
139 |
|
|
or your local CPAN mirror. |
140 |
|
|
|
141 |
|
|
=end original |
142 |
|
|
|
143 |
|
|
C<Zoidberg> は似たようなプロジェクトで perl で書かれたシェルを提供します。 |
144 |
|
|
これは perl で設定され、perl で動作します。 |
145 |
|
|
これはログインシェルと開発環境を意図しています。 |
146 |
|
|
http://pardus-larus.student.utwente.nl/~pardus/projects/zoidberg/ |
147 |
|
|
またはお近くの CPAN ミラーにあります。 |
148 |
|
|
|
149 |
|
|
=begin original |
150 |
|
|
|
151 |
|
|
The C<Shell.pm> module (distributed with Perl) makes Perl try commands |
152 |
|
|
which aren't part of the Perl language as shell commands. C<perlsh> from |
153 |
|
|
the source distribution is simplistic and uninteresting, but may still |
154 |
|
|
be what you want. |
155 |
|
|
|
156 |
|
|
=end original |
157 |
|
|
|
158 |
|
|
(Perl と一緒に配布されている) C<Shell.pm> モジュールは、Perl が Perl 言語の |
159 |
|
|
一部ではないコマンドをシェルコマンドのように試してみるようにさせます。 |
160 |
|
|
ソース配布と一緒にある C<perlsh> は単純で、面白みに欠けるものかも |
161 |
|
|
しれませんが、あなたの要求には十分かもしれません。 |
162 |
|
|
|
163 |
|
|
=head2 How do I find which modules are installed on my system? |
164 |
|
|
|
165 |
|
|
(自分のシステムに入っているモジュールを知るには?) |
166 |
|
|
|
167 |
|
|
=begin original |
168 |
|
|
|
169 |
|
|
From the command line, you can use the C<cpan> command's C<-l> switch: |
170 |
|
|
|
171 |
|
|
=end original |
172 |
|
|
|
173 |
|
|
コマンドラインからは、C<-l> オプション付きの C<cpan> コマンドが使えます: |
174 |
|
|
|
175 |
|
|
$ cpan -l |
176 |
|
|
|
177 |
|
|
=begin original |
178 |
|
|
|
179 |
|
|
You can also use C<cpan>'s C<-a> switch to create an autobundle file |
180 |
|
|
that C<CPAN.pm> understands and can use to re-install every module: |
181 |
|
|
|
182 |
|
|
=end original |
183 |
|
|
|
184 |
|
|
また、C<cpan> の C<-a> オプションを使うことで、C<CPAN.pm> が理解して、 |
185 |
|
|
全てのモジュールを再インストールするために使える autobundle ファイルも |
186 |
|
|
作れます。 |
187 |
|
|
|
188 |
|
|
$ cpan -a |
189 |
|
|
|
190 |
|
|
=begin original |
191 |
|
|
|
192 |
|
|
Inside a Perl program, you can use the C<ExtUtils::Installed> module to |
193 |
|
|
show all installed distributions, although it can take awhile to do |
194 |
|
|
its magic. The standard library which comes with Perl just shows up |
195 |
|
|
as "Perl" (although you can get those with C<Module::CoreList>). |
196 |
|
|
|
197 |
|
|
=end original |
198 |
|
|
|
199 |
|
|
Perl プログラム内では、 |
200 |
|
|
C<ExtUtils::Installed> モジュールを使うことで全てのインストールされた |
201 |
|
|
ディストリビューションを知ることが出来ますが、この魔法を使うには |
202 |
|
|
少し時間がかかります。 |
203 |
|
|
Perl と共に入る標準ライブラリは単に "Perl" として表示されます |
204 |
|
|
(しかしこれらのリストは C<Module::CoreList> で得ることが出来ます)。 |
205 |
|
|
|
206 |
|
|
use ExtUtils::Installed; |
207 |
|
|
|
208 |
|
|
my $inst = ExtUtils::Installed->new(); |
209 |
|
|
my @modules = $inst->modules(); |
210 |
|
|
|
211 |
|
|
=begin original |
212 |
|
|
|
213 |
|
|
If you want a list of all of the Perl module filenames, you |
214 |
|
|
can use C<File::Find::Rule>: |
215 |
|
|
|
216 |
|
|
=end original |
217 |
|
|
|
218 |
|
|
全ての Perl モジュールファイル名の一覧を知りたいなら、 |
219 |
|
|
C<File::Find::Rule> が利用できます: |
220 |
|
|
|
221 |
|
|
use File::Find::Rule; |
222 |
|
|
|
223 |
|
|
my @files = File::Find::Rule-> |
224 |
|
|
extras({follow => 1})-> |
225 |
|
|
file()-> |
226 |
|
|
name( '*.pm' )-> |
227 |
|
|
in( @INC ) |
228 |
|
|
; |
229 |
|
|
|
230 |
|
|
=begin original |
231 |
|
|
|
232 |
|
|
If you do not have that module, you can do the same thing |
233 |
|
|
with C<File::Find> which is part of the standard library: |
234 |
|
|
|
235 |
|
|
=end original |
236 |
|
|
|
237 |
|
|
このモジュールがない場合、標準ライブラリの一部である |
238 |
|
|
C<File::Find> を使って同じことが出来ます: |
239 |
|
|
|
240 |
|
|
use File::Find; |
241 |
|
|
my @files; |
242 |
|
|
|
243 |
|
|
find( |
244 |
|
|
{ |
245 |
|
|
wanted => sub { |
246 |
|
|
push @files, $File::Find::fullname |
247 |
|
|
if -f $File::Find::fullname && /\.pm$/ |
248 |
|
|
}, |
249 |
|
|
follow => 1, |
250 |
|
|
follow_skip => 2, |
251 |
|
|
}, |
252 |
|
|
@INC |
253 |
|
|
); |
254 |
|
|
|
255 |
|
|
print join "\n", @files; |
256 |
|
|
|
257 |
|
|
=begin original |
258 |
|
|
|
259 |
|
|
If you simply need to quickly check to see if a module is |
260 |
|
|
available, you can check for its documentation. If you can |
261 |
|
|
read the documentation the module is most likely installed. |
262 |
|
|
If you cannot read the documentation, the module might not |
263 |
|
|
have any (in rare cases): |
264 |
|
|
|
265 |
|
|
=end original |
266 |
|
|
|
267 |
|
|
単にあるモジュールが使えるかどうかを知りたいだけなら、 |
268 |
|
|
ドキュメントをチェックするという方法があります。 |
269 |
|
|
もしそのモジュールに関するドキュメントが読めるなら、 |
270 |
|
|
そのモジュールはきっとインストールされています。 |
271 |
|
|
ドキュメントが読めない場合、(まれに)モジュールにドキュメントが |
272 |
|
|
ないという可能性もあります: |
273 |
|
|
|
274 |
|
|
$ perldoc Module::Name |
275 |
|
|
|
276 |
|
|
=begin original |
277 |
|
|
|
278 |
|
|
You can also try to include the module in a one-liner to see if |
279 |
|
|
perl finds it: |
280 |
|
|
|
281 |
|
|
=end original |
282 |
|
|
|
283 |
|
|
一行野郎でモジュールを読み込めるか試すという手もあります: |
284 |
|
|
|
285 |
|
|
$ perl -MModule::Name -e1 |
286 |
|
|
|
287 |
|
|
=head2 How do I debug my Perl programs? |
288 |
|
|
|
289 |
|
|
(私の Perl プログラムをデバッグするには?) |
290 |
|
|
|
291 |
|
|
=begin original |
292 |
|
|
|
293 |
|
|
(contributed by brian d foy) |
294 |
|
|
|
295 |
|
|
=end original |
296 |
|
|
|
297 |
|
|
(brian d foy によって寄贈されました) |
298 |
|
|
|
299 |
|
|
=begin original |
300 |
|
|
|
301 |
|
|
Before you do anything else, you can help yourself by ensuring that |
302 |
|
|
you let Perl tell you about problem areas in your code. By turning |
303 |
|
|
on warnings and strictures, you can head off many problems before |
304 |
|
|
they get too big. You can find out more about these in L<strict> |
305 |
|
|
and L<warnings>. |
306 |
|
|
|
307 |
|
|
=end original |
308 |
|
|
|
309 |
|
|
他の事をする前に、あなたのコードの問題を Perl に調べさせることで |
310 |
|
|
あなたへの助けとすることが出来ます。 |
311 |
|
|
警告と厳密性をオンにすることによって、多くの問題を大事になる前に |
312 |
|
|
阻止できます。 |
313 |
|
|
これらに関する詳細は L<strict> と L<warnings> にあります。 |
314 |
|
|
|
315 |
|
|
#!/usr/bin/perl |
316 |
|
|
use strict; |
317 |
|
|
use warnings; |
318 |
|
|
|
319 |
|
|
=begin original |
320 |
|
|
|
321 |
|
|
Beyond that, the simplest debugger is the C<print> function. Use it |
322 |
|
|
to look at values as you run your program: |
323 |
|
|
|
324 |
|
|
=end original |
325 |
|
|
|
326 |
|
|
その他に、もっとも単純なデバッガは C<print> 関数です。 |
327 |
|
|
プログラム実行中に値を見るために使います: |
328 |
|
|
|
329 |
|
|
print STDERR "The value is [$value]\n"; |
330 |
|
|
|
331 |
|
|
=begin original |
332 |
|
|
|
333 |
|
|
The C<Data::Dumper> module can pretty-print Perl data structures: |
334 |
|
|
|
335 |
|
|
=end original |
336 |
|
|
|
337 |
|
|
C<Data::Dumper> モジュールは Perl のデータ構造をきれいに表示します: |
338 |
|
|
|
339 |
|
|
use Data::Dumper qw( Dumper ); |
340 |
|
|
print STDERR "The hash is " . Dumper( \%hash ) . "\n"; |
341 |
|
|
|
342 |
|
|
=begin original |
343 |
|
|
|
344 |
|
|
Perl comes with an interactive debugger, which you can start with the |
345 |
|
|
C<-d> switch. It's fully explained in L<perldebug>. |
346 |
|
|
|
347 |
|
|
=end original |
348 |
|
|
|
349 |
|
|
Perl には対話的デバッガが同梱されていて、C<-d> スイッチを付けることで |
350 |
|
|
起動できます。 |
351 |
|
|
L<perldebug> で完全に説明されています。 |
352 |
|
|
|
353 |
|
|
=begin original |
354 |
|
|
|
355 |
|
|
If you'd like a graphical user interface and you have C<Tk>, you can use |
356 |
|
|
C<ptkdb>. It's on CPAN and available for free. |
357 |
|
|
|
358 |
|
|
=end original |
359 |
|
|
|
360 |
|
|
もし GUI がほしくて、C<Tk> がある場合、C<ptkdb> が使えます。 |
361 |
|
|
これは CPAN にあり、自由に使えます。 |
362 |
|
|
|
363 |
|
|
=begin original |
364 |
|
|
|
365 |
|
|
If you need something much more sophisticated and controllable, Leon |
366 |
|
|
Brocard's C<Devel::ebug> (which you can call with the C<-D> switch as C<-Debug>) |
367 |
|
|
gives you the programmatic hooks into everything you need to write your |
368 |
|
|
own (without too much pain and suffering). |
369 |
|
|
|
370 |
|
|
=end original |
371 |
|
|
|
372 |
|
|
もっと洗練されていて制御可能なものが必要なら、Leon Brocard の |
373 |
|
|
C<Devel::ebug> (C<-D> オプションを使って C<-Debug> として呼び出せます)を使うと、 |
374 |
|
|
なんでもあなたが自分で書いたものを使って(それほどの苦痛なしに)プログラム上の |
375 |
|
|
フックを作れます。 |
376 |
|
|
|
377 |
|
|
=begin original |
378 |
|
|
|
379 |
|
|
You can also use a commercial debugger such as Affrus (Mac OS X), Komodo |
380 |
|
|
from Activestate (Windows and Mac OS X), or EPIC (most platforms). |
381 |
|
|
|
382 |
|
|
=end original |
383 |
|
|
|
384 |
|
|
Affrus (Mac OS X), Activestate Komodo (Windows と Mac OS X), EPIC |
385 |
|
|
(ほとんどのプラットフォーム) といった商用デバッガも使えます。 |
386 |
|
|
|
387 |
|
|
=head2 How do I profile my Perl programs? |
388 |
|
|
|
389 |
|
|
(私の Perl プログラムのプロファイルを取るには?) |
390 |
|
|
|
391 |
|
|
=begin original |
392 |
|
|
|
393 |
|
|
(contributed by brian d foy, updated Fri Jul 25 12:22:26 PDT 2008) |
394 |
|
|
|
395 |
|
|
=end original |
396 |
|
|
|
397 |
|
|
(brian d foy によって寄贈され、Fri Jul 25 12:22:26 PDT 2008 に |
398 |
|
|
更新されました) |
399 |
|
|
|
400 |
|
|
=begin original |
401 |
|
|
|
402 |
|
|
The C<Devel> namespace has several modules which you can use to |
403 |
|
|
profile your Perl programs. The C<Devel::DProf> module comes with Perl |
404 |
|
|
and you can invoke it with the C<-d> switch: |
405 |
|
|
|
406 |
|
|
=end original |
407 |
|
|
|
408 |
|
|
C<Devel> 名前空間には Perl プログラムをプロファイルするために使える |
409 |
|
|
いくつかのモジュールがあります。 |
410 |
|
|
C<Devel::DProf> モジュールは Perl と共に配布されていて、 |
411 |
|
|
C<-d> オプションで起動できます: |
412 |
|
|
|
413 |
|
|
perl -d:DProf program.pl |
414 |
|
|
|
415 |
|
|
=begin original |
416 |
|
|
|
417 |
|
|
After running your program under C<DProf>, you'll get a F<tmon.out> file |
418 |
|
|
with the profile data. To look at the data, you can turn it into a |
419 |
|
|
human-readable report with the C<dprofpp> program that comes with |
420 |
|
|
C<Devel::DProf>. |
421 |
|
|
|
422 |
|
|
=end original |
423 |
|
|
|
424 |
|
|
C<DProf> の元でプログラムを動かした後、プロファイルデータとして |
425 |
|
|
F<tmon.out> ファイルが得られます。 |
426 |
|
|
このデータを見るためには、C<Devel::DProf> と共に配布されている |
427 |
|
|
C<dprofpp> プログラムで人間が読める形のレポートに変換します。 |
428 |
|
|
|
429 |
|
|
dprofpp |
430 |
|
|
|
431 |
|
|
=begin original |
432 |
|
|
|
433 |
|
|
You can also do the profiling and reporting in one step with the C<-p> |
434 |
|
|
switch to C<dprofpp>: |
435 |
|
|
|
436 |
|
|
=end original |
437 |
|
|
|
438 |
|
|
また、C<dprofpp> に C<-p> オプションを付けることで、プロファイリングと |
439 |
|
|
レポートを一度に行うことも出来ます: |
440 |
|
|
|
441 |
|
|
dprofpp -p program.pl |
442 |
|
|
|
443 |
|
|
=begin original |
444 |
|
|
|
445 |
|
|
The C<Devel::NYTProf> (New York Times Profiler) does both statement |
446 |
|
|
and subroutine profiling. It's available from CPAN and you also invoke |
447 |
|
|
it with the C<-d> switch: |
448 |
|
|
|
449 |
|
|
=end original |
450 |
|
|
|
451 |
|
|
C<Devel::NYTProf> (New York Times Profiler) は文とサブルーチンの |
452 |
|
|
両方のプロファイリングを行います。 |
453 |
|
|
これは CPAN から入手可能で、やはり C<-d> オプションで起動できます: |
454 |
|
|
|
455 |
|
|
perl -d:NYTProf some_perl.pl |
456 |
|
|
|
457 |
|
|
=begin original |
458 |
|
|
|
459 |
|
|
Like C<DProf>, it creates a database of the profile information that you |
460 |
|
|
can turn into reports. The C<nytprofhtml> command turns the data into |
461 |
|
|
an HTML report similar to the C<Devel::Cover> report: |
462 |
|
|
|
463 |
|
|
=end original |
464 |
|
|
|
465 |
|
|
C<DProf> と同様、レポートに変換できるプロファイル情報のデータベースを |
466 |
|
|
作成します。 |
467 |
|
|
C<nytprofhtml> コマンドで、データを C<Devel::Cover> レポートと似たような |
468 |
|
|
HTML レポートに変換します: |
469 |
|
|
|
470 |
|
|
nytprofhtml |
471 |
|
|
|
472 |
|
|
=begin original |
473 |
|
|
|
474 |
|
|
CPAN has several other profilers that you can invoke in the same |
475 |
|
|
fashion. You might also be interested in using the C<Benchmark> to |
476 |
|
|
measure and compare code snippets. |
477 |
|
|
|
478 |
|
|
=end original |
479 |
|
|
|
480 |
|
|
CPAN には同じ形で起動できるその他のプロファイラもいくつかあります。 |
481 |
|
|
また、コード片を計測、比較するために C<Benchmark> を使うことにも |
482 |
|
|
興味があるかもしれません。 |
483 |
|
|
|
484 |
|
|
=begin original |
485 |
|
|
|
486 |
|
|
You can read more about profiling in I<Programming Perl>, chapter 20, |
487 |
|
|
or I<Mastering Perl>, chapter 5. |
488 |
|
|
|
489 |
|
|
=end original |
490 |
|
|
|
491 |
|
|
プロファイルに関するさらなることについては I<Programming Perl> の |
492 |
|
|
20 章か I<Mastering Perl> の 5 章を読んでください。 |
493 |
|
|
|
494 |
|
|
=begin original |
495 |
|
|
|
496 |
|
|
L<perldebguts> documents creating a custom debugger if you need to |
497 |
|
|
create a special sort of profiler. brian d foy describes the process |
498 |
|
|
in I<The Perl Journal>, "Creating a Perl Debugger", |
499 |
|
|
http://www.ddj.com/184404522 , and "Profiling in Perl" |
500 |
|
|
http://www.ddj.com/184404580 . |
501 |
|
|
|
502 |
|
|
=end original |
503 |
|
|
|
504 |
|
|
L<perldebguts> には、特別な種類のプロファイラが必要な場合に |
505 |
|
|
カスタムデバッガを作る方法が書かれています。 |
506 |
|
|
brian d foy は I<The Perl Journal> の "Creating a Perl Debugger", |
507 |
|
|
http://www.ddj.com/184404522 と "Profiling in Perl" |
508 |
|
|
http://www.ddj.com/184404580 で処理を記述しています。 |
509 |
|
|
|
510 |
|
|
=begin original |
511 |
|
|
|
512 |
|
|
Perl.com has two interesting articles on profiling: "Profiling Perl", |
513 |
|
|
by Simon Cozens, http://www.perl.com/lpt/a/850 and "Debugging and |
514 |
|
|
Profiling mod_perl Applications", by Frank Wiles, |
515 |
|
|
http://www.perl.com/pub/a/2006/02/09/debug_mod_perl.html . |
516 |
|
|
|
517 |
|
|
=end original |
518 |
|
|
|
519 |
|
|
Perl.com にはプロファイリングに関する二つの興味深い記事があります: |
520 |
|
|
Simon Cozens による "Profiling Perl" http://www.perl.com/lpt/a/850 と |
521 |
|
|
Frank Wiles による "Debugging and Profiling mod_perl Applications" |
522 |
|
|
http://www.perl.com/pub/a/2006/02/09/debug_mod_perl.html です。 |
523 |
|
|
|
524 |
|
|
=begin original |
525 |
|
|
|
526 |
|
|
Randal L. Schwartz writes about profiling in "Speeding up Your Perl |
527 |
|
|
Programs" for I<Unix Review>, |
528 |
|
|
http://www.stonehenge.com/merlyn/UnixReview/col49.html , and "Profiling |
529 |
|
|
in Template Toolkit via Overriding" for I<Linux Magazine>, |
530 |
|
|
http://www.stonehenge.com/merlyn/LinuxMag/col75.html . |
531 |
|
|
|
532 |
|
|
=end original |
533 |
|
|
|
534 |
|
|
Randal L. Schwartz はプロファイリングについて |
535 |
|
|
I<Unix Review> の "Speeding up Your Perl Programs" |
536 |
|
|
http://www.stonehenge.com/merlyn/UnixReview/col49.html と、 |
537 |
|
|
I<Linux Magazine> の "Profiling in Template Toolkit via Overriding" |
538 |
|
|
http://www.stonehenge.com/merlyn/LinuxMag/col75.html で書いています。 |
539 |
|
|
|
540 |
|
|
=head2 How do I cross-reference my Perl programs? |
541 |
|
|
|
542 |
|
|
(私の Perl プログラムのクロスリファレンスをとるには?) |
543 |
|
|
|
544 |
|
|
=begin original |
545 |
|
|
|
546 |
|
|
The C<B::Xref> module can be used to generate cross-reference reports |
547 |
|
|
for Perl programs. |
548 |
|
|
|
549 |
|
|
=end original |
550 |
|
|
|
551 |
|
|
C<B::Xref> モジュールが Perl プログラムに対する |
552 |
|
|
クロスリファレンスの報告を生成するのに使えます。 |
553 |
|
|
|
554 |
|
|
perl -MO=Xref[,OPTIONS] scriptname.plx |
555 |
|
|
|
556 |
|
|
=head2 Is there a pretty-printer (formatter) for Perl? |
557 |
|
|
|
558 |
|
|
(Perl 用のプリティプリンター(フォーマッター)はありますか?) |
559 |
|
|
|
560 |
|
|
=begin original |
561 |
|
|
|
562 |
|
|
C<Perltidy> is a Perl script which indents and reformats Perl scripts |
563 |
|
|
to make them easier to read by trying to follow the rules of the |
564 |
|
|
L<perlstyle>. If you write Perl scripts, or spend much time reading |
565 |
|
|
them, you will probably find it useful. It is available at |
566 |
|
|
http://perltidy.sourceforge.net . |
567 |
|
|
|
568 |
|
|
=end original |
569 |
|
|
|
570 |
|
|
C<Perltidy> は Perl スクリプトを L<perlstyle> のルールに従って |
571 |
|
|
読みやすくしようとする Perl スクリプトです。 |
572 |
|
|
Perl スクリプトを書いたとき、あるいは多くの時間を Perl スクリプトを |
573 |
|
|
読むのに費やすとき、多分これが有用です。 |
574 |
|
|
http://perltidy.sourceforge.net で入手できます。 |
575 |
|
|
|
576 |
|
|
=begin original |
577 |
|
|
|
578 |
|
|
Of course, if you simply follow the guidelines in L<perlstyle>, |
579 |
|
|
you shouldn't need to reformat. The habit of formatting your code |
580 |
|
|
as you write it will help prevent bugs. Your editor can and should |
581 |
|
|
help you with this. The perl-mode or newer cperl-mode for emacs |
582 |
|
|
can provide remarkable amounts of help with most (but not all) |
583 |
|
|
code, and even less programmable editors can provide significant |
584 |
|
|
assistance. Tom Christiansen and many other VI users swear by |
585 |
|
|
the following settings in vi and its clones: |
586 |
|
|
|
587 |
|
|
=end original |
588 |
|
|
|
589 |
|
|
もちろん、あなたが L<perlstyle> に従っているのであれば、 |
590 |
|
|
リフォーマットする必要はないでしょう。 |
591 |
|
|
自分のプログラムの書式を統一しておく習慣はバグ対策になります。 |
592 |
|
|
あなたの使っているエディターはソースのフォーマッティングを |
593 |
|
|
助けてくれるかもしれません。 |
594 |
|
|
emacs の perl モードやより新しい cperl モードは、コードの |
595 |
|
|
ほとんど(が、全部ではありません)に対して驚くほどたくさんの手助けを |
596 |
|
|
提供してくれるでしょうし、そしてそれよりも非力なプログラム可能な |
597 |
|
|
エディターでさえも明らかな手助けを提供してくれるかもしれません。 |
598 |
|
|
Tom Christiansen とその他の多くの vi 使いは vi (とそのクローン)で |
599 |
|
|
以下のような設定を使っています: |
600 |
|
|
|
601 |
|
|
set ai sw=4 |
602 |
|
|
map! ^O {^M}^[O^T |
603 |
|
|
|
604 |
|
|
=begin original |
605 |
|
|
|
606 |
|
|
Put that in your F<.exrc> file (replacing the caret characters |
607 |
|
|
with control characters) and away you go. In insert mode, ^T is |
608 |
|
|
for indenting, ^D is for undenting, and ^O is for blockdenting--as |
609 |
|
|
it were. A more complete example, with comments, can be found at |
610 |
|
|
http://www.cpan.org/authors/id/TOMC/scripts/toms.exrc.gz |
611 |
|
|
|
612 |
|
|
=end original |
613 |
|
|
|
614 |
|
|
これをあなたの F<.exrc> というファイル(キャレット文字はコントロール文字で |
615 |
|
|
置き換えます)に書き込めば OK です。 |
616 |
|
|
挿入モードでは ^T はインデントを行い、^D はアンインデントを、 |
617 |
|
|
^Oは blockdent をします。 |
618 |
|
|
コメント付きの、より完全な例は |
619 |
|
|
http://www.perl.com/CPAN-local/authors/id/TOMC/scripts/toms.exrc.gz |
620 |
|
|
にあります。 |
621 |
|
|
|
622 |
|
|
=begin original |
623 |
|
|
|
624 |
|
|
The a2ps http://www-inf.enst.fr/%7Edemaille/a2ps/black+white.ps.gz does |
625 |
|
|
lots of things related to generating nicely printed output of |
626 |
|
|
documents. |
627 |
|
|
|
628 |
|
|
=end original |
629 |
|
|
|
630 |
|
|
http://www-inf.enst.fr/%7Edemaille/a2ps/black+white.ps.gz にある a2ps は |
631 |
|
|
奇麗なドキュメントを出力するということに関して多くのことを行います。 |
632 |
|
|
|
633 |
|
|
=head2 Is there a ctags for Perl? |
634 |
|
|
|
635 |
|
|
(Perl 用の ctags はありますか?) |
636 |
|
|
|
637 |
|
|
=begin original |
638 |
|
|
|
639 |
|
|
(contributed by brian d foy) |
640 |
|
|
|
641 |
|
|
=end original |
642 |
|
|
|
643 |
|
|
(brian d foy によって寄贈されました) |
644 |
|
|
|
645 |
|
|
=begin original |
646 |
|
|
|
647 |
|
|
Ctags uses an index to quickly find things in source code, and many |
648 |
|
|
popular editors support ctags for several different languages, |
649 |
|
|
including Perl. |
650 |
|
|
|
651 |
|
|
=end original |
652 |
|
|
|
653 |
|
|
ctags はソースコード内のものを素早く探すためにインデックスを使い、多くの |
654 |
|
|
有名なエディタは Perl を含むいくつかの言語に対して ctags に対応しています。 |
655 |
|
|
|
656 |
|
|
=begin original |
657 |
|
|
|
658 |
|
|
Exuberent ctags supports Perl: http://ctags.sourceforge.net/ |
659 |
|
|
|
660 |
|
|
=end original |
661 |
|
|
|
662 |
|
|
Exuberent ctags は Perl に対応しています: http://ctags.sourceforge.net/ |
663 |
|
|
|
664 |
|
|
=begin original |
665 |
|
|
|
666 |
|
|
You might also try pltags: http://www.mscha.com/pltags.zip |
667 |
|
|
|
668 |
|
|
=end original |
669 |
|
|
|
670 |
|
|
pltags も試してみてください: http://www.mscha.com/pltags.zip |
671 |
|
|
|
672 |
|
|
=head2 Is there an IDE or Windows Perl Editor? |
673 |
|
|
|
674 |
|
|
(Perl の統合開発環境とか Windows Perl Editor はありますか?) |
675 |
|
|
|
676 |
|
|
=begin original |
677 |
|
|
|
678 |
|
|
Perl programs are just plain text, so any editor will do. |
679 |
|
|
|
680 |
|
|
=end original |
681 |
|
|
|
682 |
|
|
Perl プログラムは単なるテキストなので、どんなエディタでも作成できます。 |
683 |
|
|
|
684 |
|
|
=begin original |
685 |
|
|
|
686 |
|
|
If you're on Unix, you already have an IDE--Unix itself. The Unix |
687 |
|
|
philosophy is the philosophy of several small tools that each do one |
688 |
|
|
thing and do it well. It's like a carpenter's toolbox. |
689 |
|
|
|
690 |
|
|
=end original |
691 |
|
|
|
692 |
|
|
あなたが Unix を使っているなら、あなたはすでに統合開発環境を |
693 |
|
|
手にしています--それは Unix 自身です。 |
694 |
|
|
Unix の哲学は、一つのことをうまくこなせる小さなツールを複数 |
695 |
|
|
組み合わせることです。 |
696 |
|
|
これは大工の道具箱に似ています。 |
697 |
|
|
|
698 |
|
|
=begin original |
699 |
|
|
|
700 |
|
|
If you want an IDE, check the following (in alphabetical order, not |
701 |
|
|
order of preference): |
702 |
|
|
|
703 |
|
|
=end original |
704 |
|
|
|
705 |
|
|
統合開発環境がほしいなら、以下をチェックしてください |
706 |
|
|
(アルファベット順であって、有用な順ではありません): |
707 |
|
|
|
708 |
|
|
=over 4 |
709 |
|
|
|
710 |
|
|
=item Eclipse |
711 |
|
|
|
712 |
|
|
http://e-p-i-c.sf.net/ |
713 |
|
|
|
714 |
|
|
=begin original |
715 |
|
|
|
716 |
|
|
The Eclipse Perl Integration Project integrates Perl |
717 |
|
|
editing/debugging with Eclipse. |
718 |
|
|
|
719 |
|
|
=end original |
720 |
|
|
|
721 |
|
|
The Eclipse Perl Integration Project は Perl の編集/デバッグを Eclipse に |
722 |
|
|
統合します。 |
723 |
|
|
|
724 |
|
|
=item Enginsite |
725 |
|
|
|
726 |
|
|
http://www.enginsite.com/ |
727 |
|
|
|
728 |
|
|
=begin original |
729 |
|
|
|
730 |
|
|
Perl Editor by EngInSite is a complete integrated development |
731 |
|
|
environment (IDE) for creating, testing, and debugging Perl scripts; |
732 |
|
|
the tool runs on Windows 9x/NT/2000/XP or later. |
733 |
|
|
|
734 |
|
|
=end original |
735 |
|
|
|
736 |
|
|
EngInSite の Perl Editor Perl スクリプトを作成・テスト・デバッグするための |
737 |
|
|
完全な統合開発環境(IDE)です; ツールは Windows 9x/NT/2000/XP 移行で |
738 |
|
|
動作します。 |
739 |
|
|
|
740 |
|
|
=item Komodo |
741 |
|
|
|
742 |
|
|
http://www.ActiveState.com/Products/Komodo/ |
743 |
|
|
|
744 |
|
|
=begin original |
745 |
|
|
|
746 |
|
|
ActiveState's cross-platform (as of October 2004, that's Windows, Linux, |
747 |
|
|
and Solaris), multi-language IDE has Perl support, including a regular expression |
748 |
|
|
debugger and remote debugging. |
749 |
|
|
|
750 |
|
|
=end original |
751 |
|
|
|
752 |
|
|
ActiveState のクロスプラットフォーム(2004 年 10 月現在 |
753 |
|
|
Windows, Linux, Solaris) 多言語 IDE は、 |
754 |
|
|
正規表現デバッガ、リモートデバッグを含む Perl サポートがあります。 |
755 |
|
|
|
756 |
|
|
=item Notepad++ |
757 |
|
|
|
758 |
|
|
http://notepad-plus.sourceforge.net/ |
759 |
|
|
|
760 |
|
|
=item Open Perl IDE |
761 |
|
|
|
762 |
|
|
http://open-perl-ide.sourceforge.net/ |
763 |
|
|
|
764 |
|
|
=begin original |
765 |
|
|
|
766 |
|
|
Open Perl IDE is an integrated development environment for writing |
767 |
|
|
and debugging Perl scripts with ActiveState's ActivePerl distribution |
768 |
|
|
under Windows 95/98/NT/2000. |
769 |
|
|
|
770 |
|
|
=end original |
771 |
|
|
|
772 |
|
|
Open Perl IDE は Windows 95/98/NT/2000 で動作する ActiveState の |
773 |
|
|
ActivePerl で Perl スクリプトを書いたりデバッグしたりするための |
774 |
|
|
統合開発環境です。 |
775 |
|
|
|
776 |
|
|
=item OptiPerl |
777 |
|
|
|
778 |
|
|
http://www.optiperl.com/ |
779 |
|
|
|
780 |
|
|
=begin original |
781 |
|
|
|
782 |
|
|
OptiPerl is a Windows IDE with simulated CGI environment, including |
783 |
|
|
debugger and syntax highlighting editor. |
784 |
|
|
|
785 |
|
|
=end original |
786 |
|
|
|
787 |
|
|
OptiPerl は擬似 CGI 環境を持つ Windows 用 IDE で、 |
788 |
|
|
デバッガと文法によって色付けされるエディタを含みます。 |
789 |
|
|
|
790 |
|
|
=item Padre |
791 |
|
|
|
792 |
|
|
http://padre.perlide.org/ |
793 |
|
|
|
794 |
|
|
=begin original |
795 |
|
|
|
796 |
|
|
Padre is cross-platform IDE for Perl written in Perl using wxWidgets to provide |
797 |
|
|
a native look and feel. It's open source under the Artistic License. |
798 |
|
|
|
799 |
|
|
=end original |
800 |
|
|
|
801 |
|
|
Padre は、ネイティブな見た目を提供するために wxWidgets を使って Perl で |
802 |
|
|
書かれた Perl のためのクロスプラットフォーム IDE です。 |
803 |
|
|
|
804 |
|
|
=item PerlBuilder |
805 |
|
|
|
806 |
|
|
http://www.solutionsoft.com/perl.htm |
807 |
|
|
|
808 |
|
|
=begin original |
809 |
|
|
|
810 |
|
|
PerlBuilder is an integrated development environment for Windows that |
811 |
|
|
supports Perl development. |
812 |
|
|
|
813 |
|
|
=end original |
814 |
|
|
|
815 |
|
|
PerlBuilder は Windows 用統合開発環境で、Perl の開発にも対応しています。 |
816 |
|
|
|
817 |
|
|
=item visiPerl+ |
818 |
|
|
|
819 |
|
|
http://helpconsulting.net/visiperl/ |
820 |
|
|
|
821 |
|
|
=begin original |
822 |
|
|
|
823 |
|
|
From Help Consulting, for Windows. |
824 |
|
|
|
825 |
|
|
=end original |
826 |
|
|
|
827 |
|
|
Help Consulting 製で、Windows 用です。 |
828 |
|
|
|
829 |
|
|
=item Visual Perl |
830 |
|
|
|
831 |
|
|
http://www.activestate.com/Products/Visual_Perl/ |
832 |
|
|
|
833 |
|
|
=begin original |
834 |
|
|
|
835 |
|
|
Visual Perl is a Visual Studio.NET plug-in from ActiveState. |
836 |
|
|
|
837 |
|
|
=end original |
838 |
|
|
|
839 |
|
|
Visual Perl は ActiveState 製で、Visual Studio.NET へのプラグインです。 |
840 |
|
|
|
841 |
|
|
=item Zeus |
842 |
|
|
|
843 |
|
|
http://www.zeusedit.com/lookmain.html |
844 |
|
|
|
845 |
|
|
=begin original |
846 |
|
|
|
847 |
|
|
Zeus for Window is another Win32 multi-language editor/IDE |
848 |
|
|
that comes with support for Perl: |
849 |
|
|
|
850 |
|
|
=end original |
851 |
|
|
|
852 |
|
|
Zeus for Window は Perl にも対応した、もう一つの Win32 複数言語 |
853 |
|
|
エディタ/IDEです。 |
854 |
|
|
|
855 |
|
|
=back |
856 |
|
|
|
857 |
|
|
=begin original |
858 |
|
|
|
859 |
|
|
For editors: if you're on Unix you probably have vi or a vi clone |
860 |
|
|
already, and possibly an emacs too, so you may not need to download |
861 |
|
|
anything. In any emacs the cperl-mode (M-x cperl-mode) gives you |
862 |
|
|
perhaps the best available Perl editing mode in any editor. |
863 |
|
|
|
864 |
|
|
=end original |
865 |
|
|
|
866 |
|
|
エディタ使いへ: あなたが Unix を使っているなら、おそらく vi か |
867 |
|
|
vi クローンがすでにあるはずで、emacs もあるかもしれません。 |
868 |
|
|
それで、あなたは何もダウンロードする必要はないかもしれません。 |
869 |
|
|
あらゆるバージョンの emacs で使える cperl-mode (M-x cperl-mode) は |
870 |
|
|
おそらくエディタでの Perl 編集モードの中で最高のものでしょう。 |
871 |
|
|
|
872 |
|
|
=begin original |
873 |
|
|
|
874 |
|
|
If you are using Windows, you can use any editor that lets you work |
875 |
|
|
with plain text, such as NotePad or WordPad. Word processors, such as |
876 |
|
|
Microsoft Word or WordPerfect, typically do not work since they insert |
877 |
|
|
all sorts of behind-the-scenes information, although some allow you to |
878 |
|
|
save files as "Text Only". You can also download text editors designed |
879 |
|
|
specifically for programming, such as Textpad ( |
880 |
|
|
http://www.textpad.com/ ) and UltraEdit ( http://www.ultraedit.com/ ), |
881 |
|
|
among others. |
882 |
|
|
|
883 |
|
|
=end original |
884 |
|
|
|
885 |
|
|
Windows を使っているのなら、NotePad や WordPad といった |
886 |
|
|
プレーンテキストを扱えるエディタを使うことが出来ます。 |
887 |
|
|
Microsoft Word や WordPerfect といったワードプロセッサは |
888 |
|
|
一般的には使えません。なぜなら色々な「裏方の」情報を追加するからです。 |
889 |
|
|
ただし、"Text Only" としてファイルをセーブできるものもあります。 |
890 |
|
|
また、Textpad ( http://www.textpad.com/ ) や UltraEdit |
891 |
|
|
( http://www.ultraedit.com/ ) といったプログラミングに特化した |
892 |
|
|
テキストエディタをダウンロードすることもできます。 |
893 |
|
|
|
894 |
|
|
=begin original |
895 |
|
|
|
896 |
|
|
If you are using MacOS, the same concerns apply. MacPerl (for Classic |
897 |
|
|
environments) comes with a simple editor. Popular external editors are |
898 |
|
|
BBEdit ( http://www.bbedit.com/ ) or Alpha ( |
899 |
|
|
http://www.his.com/~jguyer/Alpha/Alpha8.html ). MacOS X users can use |
900 |
|
|
Unix editors as well. |
901 |
|
|
|
902 |
|
|
=end original |
903 |
|
|
|
904 |
|
|
MacOS を使っているなら、同様の考え方が適用されます。 |
905 |
|
|
(Classic 環境用の)MacPerl にはシンプルなエディタが付いています。 |
906 |
|
|
有名な外部エディタとしては BBEdit ( http://www.bbedit.com/ ) や |
907 |
|
|
Alpha ( http://www.his.com/~jguyer/Alpha/Alpha8.html ) があります。 |
908 |
|
|
MacOS X ユーザーは Unix エディタも使えます。 |
909 |
|
|
|
910 |
|
|
=over 4 |
911 |
|
|
|
912 |
|
|
=item GNU Emacs |
913 |
|
|
|
914 |
|
|
http://www.gnu.org/software/emacs/windows/ntemacs.html |
915 |
|
|
|
916 |
|
|
=item MicroEMACS |
917 |
|
|
|
918 |
|
|
http://www.microemacs.de/ |
919 |
|
|
|
920 |
|
|
=item XEmacs |
921 |
|
|
|
922 |
|
|
http://www.xemacs.org/Download/index.html |
923 |
|
|
|
924 |
|
|
=item Jed |
925 |
|
|
|
926 |
|
|
http://space.mit.edu/~davis/jed/ |
927 |
|
|
|
928 |
|
|
=back |
929 |
|
|
|
930 |
|
|
=begin original |
931 |
|
|
|
932 |
|
|
or a vi clone such as |
933 |
|
|
|
934 |
|
|
=end original |
935 |
|
|
|
936 |
|
|
あるいは以下のような vi クローンもあります: |
937 |
|
|
|
938 |
|
|
=over 4 |
939 |
|
|
|
940 |
|
|
=item Elvis |
941 |
|
|
|
942 |
|
|
ftp://ftp.cs.pdx.edu/pub/elvis/ http://www.fh-wedel.de/elvis/ |
943 |
|
|
|
944 |
|
|
=item Vile |
945 |
|
|
|
946 |
|
|
http://dickey.his.com/vile/vile.html |
947 |
|
|
|
948 |
|
|
=item Vim |
949 |
|
|
|
950 |
|
|
http://www.vim.org/ |
951 |
|
|
|
952 |
|
|
=back |
953 |
|
|
|
954 |
|
|
=begin original |
955 |
|
|
|
956 |
|
|
For vi lovers in general, Windows or elsewhere: |
957 |
|
|
|
958 |
|
|
=end original |
959 |
|
|
|
960 |
|
|
一般的な、Windows やその他の vi 愛好者のために: |
961 |
|
|
|
962 |
|
|
http://www.thomer.com/thomer/vi/vi.html |
963 |
|
|
|
964 |
|
|
=begin original |
965 |
|
|
|
966 |
|
|
nvi ( http://www.bostic.com/vi/ , available from CPAN in src/misc/) is |
967 |
|
|
yet another vi clone, unfortunately not available for Windows, but in |
968 |
|
|
Unix platforms you might be interested in trying it out, firstly because |
969 |
|
|
strictly speaking it is not a vi clone, it is the real vi, or the new |
970 |
|
|
incarnation of it, and secondly because you can embed Perl inside it |
971 |
|
|
to use Perl as the scripting language. nvi is not alone in this, |
972 |
|
|
though: at least also vim and vile offer an embedded Perl. |
973 |
|
|
|
974 |
|
|
=end original |
975 |
|
|
|
976 |
|
|
nvi (http://www.bostic.com/vi/ , CPAN の src/misc/ にもあります)は |
977 |
|
|
vi クローンの一つで、残念ながら Windows では動作しませんが、 |
978 |
|
|
Unix プラットフォームを使っているなら試してみるべきです。 |
979 |
|
|
第一の理由としては、厳密には vi クローンではないものの、 |
980 |
|
|
実際は vi、あるいは vi の子孫であるからです。 |
981 |
|
|
第二の理由としては、Perl を内蔵していて、Perl をスクリプト言語として |
982 |
|
|
使えるからです。 |
983 |
|
|
しかし、nvi はこれらの機能をもつ唯一のものではありません。 |
984 |
|
|
少なくとも vim と vile も内蔵 Perl を提供しています。 |
985 |
|
|
|
986 |
|
|
=begin original |
987 |
|
|
|
988 |
|
|
The following are Win32 multilanguage editor/IDEs that support Perl: |
989 |
|
|
|
990 |
|
|
=end original |
991 |
|
|
|
992 |
|
|
以下は Perl をサポートしている Win32 多言語エディタ/IDE です。 |
993 |
|
|
|
994 |
|
|
=over 4 |
995 |
|
|
|
996 |
|
|
=item Codewright |
997 |
|
|
|
998 |
|
|
http://www.borland.com/codewright/ |
999 |
|
|
|
1000 |
|
|
=item MultiEdit |
1001 |
|
|
|
1002 |
|
|
http://www.MultiEdit.com/ |
1003 |
|
|
|
1004 |
|
|
=item SlickEdit |
1005 |
|
|
|
1006 |
|
|
http://www.slickedit.com/ |
1007 |
|
|
|
1008 |
|
|
=item ConTEXT |
1009 |
|
|
|
1010 |
|
|
http://www.contexteditor.org/ |
1011 |
|
|
|
1012 |
|
|
=back |
1013 |
|
|
|
1014 |
|
|
=begin original |
1015 |
|
|
|
1016 |
|
|
There is also a toyedit Text widget based editor written in Perl |
1017 |
|
|
that is distributed with the Tk module on CPAN. The ptkdb |
1018 |
|
|
( http://ptkdb.sourceforge.net/ ) is a Perl/tk based debugger that |
1019 |
|
|
acts as a development environment of sorts. Perl Composer |
1020 |
|
|
( http://perlcomposer.sourceforge.net/ ) is an IDE for Perl/Tk |
1021 |
|
|
GUI creation. |
1022 |
|
|
|
1023 |
|
|
=end original |
1024 |
|
|
|
1025 |
|
|
CPAN で Tk モジュールと共に配布されている、Perl で書かれた |
1026 |
|
|
toyedit Text ウィジェットベースのエディタがあります。 |
1027 |
|
|
ptkdb( http://ptkdb.sourceforge.net/ ) は 開発環境として振舞う |
1028 |
|
|
Perl/tk ベースのデバッガです。 |
1029 |
|
|
Perl Composer ( http://perlcomposer.sourceforge.net/vperl.html )は |
1030 |
|
|
Perl/Tk GUI を使った IDE です。 |
1031 |
|
|
|
1032 |
|
|
=begin original |
1033 |
|
|
|
1034 |
|
|
In addition to an editor/IDE you might be interested in a more |
1035 |
|
|
powerful shell environment for Win32. Your options include |
1036 |
|
|
|
1037 |
|
|
=end original |
1038 |
|
|
|
1039 |
|
|
エディタ/統合開発環境に加えて、Win32 環境でのより強力な |
1040 |
|
|
シェル環境に興味があるかもしれません。 |
1041 |
|
|
選択肢としては以下のものがあります: |
1042 |
|
|
|
1043 |
|
|
=over 4 |
1044 |
|
|
|
1045 |
|
|
=item Bash |
1046 |
|
|
|
1047 |
|
|
=begin original |
1048 |
|
|
|
1049 |
|
|
from the Cygwin package ( http://sources.redhat.com/cygwin/ ) |
1050 |
|
|
|
1051 |
|
|
=end original |
1052 |
|
|
|
1053 |
|
|
Cygwin パッケージ ( http://sources.redhat.com/cygwin/ ) から。 |
1054 |
|
|
|
1055 |
|
|
=item Ksh |
1056 |
|
|
|
1057 |
|
|
=begin original |
1058 |
|
|
|
1059 |
|
|
from the MKS Toolkit ( http://www.mkssoftware.com/ ), or the Bourne shell of |
1060 |
|
|
the U/WIN environment ( http://www.research.att.com/sw/tools/uwin/ ) |
1061 |
|
|
|
1062 |
|
|
=end original |
1063 |
|
|
|
1064 |
|
|
MKS ツールキット ( http://www.mkssoftware.com/ )か、 |
1065 |
|
|
U/WIN 環境 ( http://www.research.att.com/sw/tools/uwin/ ) の |
1066 |
|
|
Bourne shell から。 |
1067 |
|
|
|
1068 |
|
|
=item Tcsh |
1069 |
|
|
|
1070 |
|
|
=begin original |
1071 |
|
|
|
1072 |
|
|
ftp://ftp.astron.com/pub/tcsh/ , see also |
1073 |
|
|
http://www.primate.wisc.edu/software/csh-tcsh-book/ |
1074 |
|
|
|
1075 |
|
|
=end original |
1076 |
|
|
|
1077 |
|
|
ftp://ftp.astron.com/pub/tcsh/ ; |
1078 |
|
|
http://www.primate.wisc.edu/software/csh-tcsh-book/ も参照してください。 |
1079 |
|
|
|
1080 |
|
|
=item Zsh |
1081 |
|
|
|
1082 |
|
|
http://www.zsh.org/ |
1083 |
|
|
|
1084 |
|
|
=back |
1085 |
|
|
|
1086 |
|
|
=begin original |
1087 |
|
|
|
1088 |
|
|
MKS and U/WIN are commercial (U/WIN is free for educational and |
1089 |
|
|
research purposes), Cygwin is covered by the GNU General Public |
1090 |
|
|
License (but that shouldn't matter for Perl use). The Cygwin, MKS, |
1091 |
|
|
and U/WIN all contain (in addition to the shells) a comprehensive set |
1092 |
|
|
of standard Unix toolkit utilities. |
1093 |
|
|
|
1094 |
|
|
=end original |
1095 |
|
|
|
1096 |
|
|
MKS とU/WIN は商用(U/WIN は教育・研究目的には無料)で、 |
1097 |
|
|
Cygwin は GNU General Public License で配布されています |
1098 |
|
|
(しかしこれは Perl の使用には関係ないはずです)。 |
1099 |
|
|
Cygwin, MSK, U/WIN は全て(シェルに加えて)広範囲な標準 Unix |
1100 |
|
|
ツールキットを含んでいます。 |
1101 |
|
|
|
1102 |
|
|
=begin original |
1103 |
|
|
|
1104 |
|
|
If you're transferring text files between Unix and Windows using FTP |
1105 |
|
|
be sure to transfer them in ASCII mode so the ends of lines are |
1106 |
|
|
appropriately converted. |
1107 |
|
|
|
1108 |
|
|
=end original |
1109 |
|
|
|
1110 |
|
|
Unix と Windows の間でテキストファイルを FTP で転送する場合、 |
1111 |
|
|
改行コードを適切に変更するために ASCII モードにしてください。 |
1112 |
|
|
|
1113 |
|
|
=begin original |
1114 |
|
|
|
1115 |
|
|
On Mac OS the MacPerl Application comes with a simple 32k text editor |
1116 |
|
|
that behaves like a rudimentary IDE. In contrast to the MacPerl Application |
1117 |
|
|
the MPW Perl tool can make use of the MPW Shell itself as an editor (with |
1118 |
|
|
no 32k limit). |
1119 |
|
|
|
1120 |
|
|
=end original |
1121 |
|
|
|
1122 |
|
|
Mac OS では MacPerl Application は基本的な IDE のように振舞う |
1123 |
|
|
シンプルな 32k テキストエディタがついています。 |
1124 |
|
|
MacPerl Application と対照的に、MPW Perl tool は MPW Shell 自身を |
1125 |
|
|
(32k の制限なしに)エディタとして使えます。 |
1126 |
|
|
|
1127 |
|
|
=over 4 |
1128 |
|
|
|
1129 |
|
|
=item Affrus |
1130 |
|
|
|
1131 |
|
|
=begin original |
1132 |
|
|
|
1133 |
|
|
is a full Perl development environment with full debugger support |
1134 |
|
|
( http://www.latenightsw.com ). |
1135 |
|
|
|
1136 |
|
|
=end original |
1137 |
|
|
|
1138 |
|
|
は、完全なデバッガサポート付きの完全な Perl 開発環境です |
1139 |
|
|
( http://www.latenightsw.com )。 |
1140 |
|
|
|
1141 |
|
|
=item Alpha |
1142 |
|
|
|
1143 |
|
|
=begin original |
1144 |
|
|
|
1145 |
|
|
is an editor, written and extensible in Tcl, that nonetheless has |
1146 |
|
|
built in support for several popular markup and programming languages |
1147 |
|
|
including Perl and HTML ( http://www.his.com/~jguyer/Alpha/Alpha8.html ). |
1148 |
|
|
|
1149 |
|
|
=end original |
1150 |
|
|
|
1151 |
|
|
これはエディタで、Tcl で書かれており、拡張可能です。 |
1152 |
|
|
それでもいくつかの有名なマークアップ言語とプログラミング言語 |
1153 |
|
|
( Perl と HTML を含みます)への対応を内蔵しています |
1154 |
|
|
( http://www.his.com/~jguyer/Alpha/Alpha8.html )。 |
1155 |
|
|
|
1156 |
|
|
=item BBEdit and BBEdit Lite |
1157 |
|
|
|
1158 |
|
|
=begin original |
1159 |
|
|
|
1160 |
|
|
are text editors for Mac OS that have a Perl sensitivity mode |
1161 |
|
|
( http://web.barebones.com/ ). |
1162 |
|
|
|
1163 |
|
|
=end original |
1164 |
|
|
|
1165 |
|
|
これは Mac OS で動作するテキストエディタで、 |
1166 |
|
|
Perl 用のモードがあります( http://web.barebones.com/ )。 |
1167 |
|
|
|
1168 |
|
|
=back |
1169 |
|
|
|
1170 |
|
|
=head2 Where can I get Perl macros for vi? |
1171 |
|
|
|
1172 |
|
|
(vi 用の Perl マクロはどこで入手できますか?) |
1173 |
|
|
|
1174 |
|
|
=begin original |
1175 |
|
|
|
1176 |
|
|
For a complete version of Tom Christiansen's vi configuration file, |
1177 |
|
|
see http://www.cpan.org/authors/Tom_Christiansen/scripts/toms.exrc.gz , |
1178 |
|
|
the standard benchmark file for vi emulators. The file runs best with nvi, |
1179 |
|
|
the current version of vi out of Berkeley, which incidentally can be built |
1180 |
|
|
with an embedded Perl interpreter--see http://www.cpan.org/src/misc/ . |
1181 |
|
|
|
1182 |
|
|
=end original |
1183 |
|
|
|
1184 |
|
|
Tom Christiansen の vi コンフィグレーションファイルの完全なものは |
1185 |
|
|
vi エミュレータの標準ベンチマークファイルである |
1186 |
|
|
http://www.cpan.org/authors/Tom_Christiansen/scripts/toms.exrc.gz |
1187 |
|
|
を参照してください。 |
1188 |
|
|
これは Berkeley の外にあるviのカレントバージョンである nvi で |
1189 |
|
|
最もうまく実行されます。 |
1190 |
|
|
nvi は組み込みの Perl インタプリタをつけてビルドすることもできます。 |
1191 |
|
|
http://www.cpan.org/src/misc/ を参照してください。 |
1192 |
|
|
|
1193 |
|
|
=head2 Where can I get perl-mode for emacs? |
1194 |
|
|
|
1195 |
|
|
(emacs の perl-mode はどこで入手できますか?) |
1196 |
|
|
|
1197 |
|
|
=begin original |
1198 |
|
|
|
1199 |
|
|
Since Emacs version 19 patchlevel 22 or so, there have been both a |
1200 |
|
|
perl-mode.el and support for the Perl debugger built in. These should |
1201 |
|
|
come with the standard Emacs 19 distribution. |
1202 |
|
|
|
1203 |
|
|
=end original |
1204 |
|
|
|
1205 |
|
|
Emacs のバージョン 19 パッチレベル 22 から、perl-mode.el と組み込みの Perl |
1206 |
|
|
デバッガをサポートしています。 |
1207 |
|
|
これらは標準の Emacs19 配布セットと一緒にあるはずです。 |
1208 |
|
|
|
1209 |
|
|
=begin original |
1210 |
|
|
|
1211 |
|
|
In the Perl source directory, you'll find a directory called "emacs", |
1212 |
|
|
which contains a cperl-mode that color-codes keywords, provides |
1213 |
|
|
context-sensitive help, and other nifty things. |
1214 |
|
|
|
1215 |
|
|
=end original |
1216 |
|
|
|
1217 |
|
|
Perlのソースディレクトリには、"emacs" というディレクトリがあって、 |
1218 |
|
|
そこにはキーワードをカラー表示したり、コンテキスト依存な |
1219 |
|
|
ヘルプなどのご機嫌なことを提供する cperl-mode があります。 |
1220 |
|
|
|
1221 |
|
|
=begin original |
1222 |
|
|
|
1223 |
|
|
Note that the perl-mode of emacs will have fits with C<"main'foo"> |
1224 |
|
|
(single quote), and mess up the indentation and highlighting. You |
1225 |
|
|
are probably using C<"main::foo"> in new Perl code anyway, so this |
1226 |
|
|
shouldn't be an issue. |
1227 |
|
|
|
1228 |
|
|
=end original |
1229 |
|
|
|
1230 |
|
|
emacs の perl-mode は C<"main'foo">(シングルクォート)スタイルを扱うもので、 |
1231 |
|
|
インデントやハイライトをおかしくしてしまうことに注意してください。 |
1232 |
|
|
いずれにしろ、C<"main::foo">を使うべきでしょう。 |
1233 |
|
|
|
1234 |
|
|
=head2 How can I use curses with Perl? |
1235 |
|
|
|
1236 |
|
|
(Perl で curses を使うには?) |
1237 |
|
|
|
1238 |
|
|
=begin original |
1239 |
|
|
|
1240 |
|
|
The Curses module from CPAN provides a dynamically loadable object |
1241 |
|
|
module interface to a curses library. A small demo can be found at the |
1242 |
|
|
directory http://www.cpan.org/authors/Tom_Christiansen/scripts/rep.gz ; |
1243 |
|
|
this program repeats a command and updates the screen as needed, rendering |
1244 |
|
|
B<rep ps axu> similar to B<top>. |
1245 |
|
|
|
1246 |
|
|
=end original |
1247 |
|
|
|
1248 |
|
|
CPAN にある Curses モジュールは、curses ライブラリに対する動的に |
1249 |
|
|
ロード可能なオブジェクトモジュールインターフェースを提供します。 |
1250 |
|
|
ちょっとしたデモが |
1251 |
|
|
http://www.cpan.org/authors/Tom_Christiansen/scripts/rep.gz |
1252 |
|
|
にあります。 |
1253 |
|
|
このプログラムはコマンドを繰り返し、必要に応じて |
1254 |
|
|
画面を更新し、B<top> と同じく B<rep ps axu> をレンダリングします。 |
1255 |
|
|
|
1256 |
|
|
=head2 How can I write a GUI (X, Tk, Gtk, etc.) in Perl? |
1257 |
|
|
X<GUI> X<Tk> X<Wx> X<WxWidgets> X<Gtk> X<Gtk2> X<CamelBones> X<Qt> |
1258 |
|
|
|
1259 |
|
|
(Perl で GUI (X, Tk, Gtk など) を書くには?) |
1260 |
|
|
|
1261 |
|
|
=begin original |
1262 |
|
|
|
1263 |
|
|
(contributed by Ben Morrow) |
1264 |
|
|
|
1265 |
|
|
=end original |
1266 |
|
|
|
1267 |
|
|
(Ben Morrow によって寄贈されました) |
1268 |
|
|
|
1269 |
|
|
=begin original |
1270 |
|
|
|
1271 |
|
|
There are a number of modules which let you write GUIs in Perl. Most |
1272 |
|
|
GUI toolkits have a perl interface: an incomplete list follows. |
1273 |
|
|
|
1274 |
|
|
=end original |
1275 |
|
|
|
1276 |
|
|
Perl で GUI を書くための多くのモジュールがあります。 |
1277 |
|
|
ほとんどの GUI ツールキットには perl インターフェースがあります: |
1278 |
|
|
以下に不完全なリストを示します。 |
1279 |
|
|
|
1280 |
|
|
=over 4 |
1281 |
|
|
|
1282 |
|
|
=item Tk |
1283 |
|
|
|
1284 |
|
|
=begin original |
1285 |
|
|
|
1286 |
|
|
This works under Unix and Windows, and the current version doesn't |
1287 |
|
|
look half as bad under Windows as it used to. Some of the gui elements |
1288 |
|
|
still don't 'feel' quite right, though. The interface is very natural |
1289 |
|
|
and 'perlish', making it easy to use in small scripts that just need a |
1290 |
|
|
simple gui. It hasn't been updated in a while. |
1291 |
|
|
|
1292 |
|
|
=end original |
1293 |
|
|
|
1294 |
|
|
これは Unix と Windows で動作し、現在のバージョンは Windows でも以前のように |
1295 |
|
|
悪くはないです。 |
1296 |
|
|
しかし、GUI 要素には完全に正しい「感じ」ではないものもあります。 |
1297 |
|
|
インターフェースはとても自然で「perl っぽい」もので、単純な GUI が |
1298 |
|
|
ほしいだけの小さいスクリプトで簡単に使えます。 |
1299 |
|
|
これはしばらくの間更新されていません。 |
1300 |
|
|
|
1301 |
|
|
=item Wx |
1302 |
|
|
|
1303 |
|
|
=begin original |
1304 |
|
|
|
1305 |
|
|
This is a Perl binding for the cross-platform wxWidgets toolkit |
1306 |
|
|
( http://www.wxwidgets.org ). It works under Unix, Win32 and Mac OS X, |
1307 |
|
|
using native widgets (Gtk under Unix). The interface follows the C++ |
1308 |
|
|
interface closely, but the documentation is a little sparse for someone |
1309 |
|
|
who doesn't know the library, mostly just referring you to the C++ |
1310 |
|
|
documentation. |
1311 |
|
|
|
1312 |
|
|
=end original |
1313 |
|
|
|
1314 |
|
|
これは クロスプラットフォーム wxWidgets ツールキット |
1315 |
|
|
( http://www.wxwidgets.org ) の Perl バインディングです。 |
1316 |
|
|
これは ネイティブなウィジェット(Unix では Gtk) を使って、 |
1317 |
|
|
Unix, Win32, Mac OS X で動作します。 |
1318 |
|
|
インターフェースは C++ インターフェースに近いですが、 |
1319 |
|
|
ドキュメントはライブラリを知らない人にとっては少々手薄なので、 |
1320 |
|
|
たいていは単に C++ ドキュメントを参照することになるでしょう。 |
1321 |
|
|
|
1322 |
|
|
=item Gtk and Gtk2 |
1323 |
|
|
|
1324 |
|
|
=begin original |
1325 |
|
|
|
1326 |
|
|
These are Perl bindings for the Gtk toolkit ( http://www.gtk.org ). The |
1327 |
|
|
interface changed significantly between versions 1 and 2 so they have |
1328 |
|
|
separate Perl modules. It runs under Unix, Win32 and Mac OS X (currently |
1329 |
|
|
it requires an X server on Mac OS, but a 'native' port is underway), and |
1330 |
|
|
the widgets look the same on every plaform: i.e., they don't match the |
1331 |
|
|
native widgets. As with Wx, the Perl bindings follow the C API closely, |
1332 |
|
|
and the documentation requires you to read the C documentation to |
1333 |
|
|
understand it. |
1334 |
|
|
|
1335 |
|
|
=end original |
1336 |
|
|
|
1337 |
|
|
Gtk ツールキット ( http://www.gtk.org ) の Perl バインディングがあります。 |
1338 |
|
|
バージョン 1 と 2 でインターフェースが大きく変わったので、個別の Perl |
1339 |
|
|
モジュールになっています。 |
1340 |
|
|
これは Unix, Win32, Mac OS X で動作し(現在のところ Mac OS X では |
1341 |
|
|
X サーバーが必要ですが、「ネイティブ」ポートも進行中です)、ウィジェットは |
1342 |
|
|
どのプラットフォームでも同じような見た目になります(つまり、ネイティブの |
1343 |
|
|
ウィジェットとは一致しません)。 |
1344 |
|
|
Wx と同様、Perl バインディングは C API に似ていて、これを理解するためには |
1345 |
|
|
C のドキュメントを読む必要があります。 |
1346 |
|
|
|
1347 |
|
|
=item Win32::GUI |
1348 |
|
|
|
1349 |
|
|
=begin original |
1350 |
|
|
|
1351 |
|
|
This provides access to most of the Win32 GUI widgets from Perl. |
1352 |
|
|
Obviously, it only runs under Win32, and uses native widgets. The Perl |
1353 |
|
|
interface doesn't really follow the C interface: it's been made more |
1354 |
|
|
Perlish, and the documentation is pretty good. More advanced stuff may |
1355 |
|
|
require familiarity with the C Win32 APIs, or reference to MSDN. |
1356 |
|
|
|
1357 |
|
|
=end original |
1358 |
|
|
|
1359 |
|
|
これは Perl から Win32 GUI ウィジェットのほとんどへのアクセスを提供します。 |
1360 |
|
|
明らかに、これは Win32 でのみ動作し、ネイティブなウィジェットを使います。 |
1361 |
|
|
Perl のインターフェースは C のインターフェースに本当に従ってはいません: |
1362 |
|
|
これはより Perl っぽく、ドキュメントもかなりよく出来ています。 |
1363 |
|
|
より高度な機能を使うためには C Win32 API に親しんでいるか、MSDN を |
1364 |
|
|
参照する必要があります。 |
1365 |
|
|
|
1366 |
|
|
=item CamelBones |
1367 |
|
|
|
1368 |
|
|
=begin original |
1369 |
|
|
|
1370 |
|
|
CamelBones ( http://camelbones.sourceforge.net ) is a Perl interface to |
1371 |
|
|
Mac OS X's Cocoa GUI toolkit, and as such can be used to produce native |
1372 |
|
|
GUIs on Mac OS X. It's not on CPAN, as it requires frameworks that |
1373 |
|
|
CPAN.pm doesn't know how to install, but installation is via the |
1374 |
|
|
standard OSX package installer. The Perl API is, again, very close to |
1375 |
|
|
the ObjC API it's wrapping, and the documentation just tells you how to |
1376 |
|
|
translate from one to the other. |
1377 |
|
|
|
1378 |
|
|
=end original |
1379 |
|
|
|
1380 |
|
|
CamelBones ( http://camelbones.sourceforge.net ) は Mac OS X の Cocoa GUI への |
1381 |
|
|
Perl のインターフェースで、Mac OS X でのネイティブな GUI の生成に使えます。 |
1382 |
|
|
これは CPAN.pm がどのようにインストールすればよいか知らないフレームワークを |
1383 |
|
|
必要とするので CPAN にはありませんが、標準 OSX パッケージインストーラ経由で |
1384 |
|
|
インストールします。 |
1385 |
|
|
再び、Perl API はそれがラッピングしている ObjC API ととても近いので、 |
1386 |
|
|
ドキュメントは単にお互いをどう変換すればいいかについて書いています。 |
1387 |
|
|
|
1388 |
|
|
=item Qt |
1389 |
|
|
|
1390 |
|
|
=begin original |
1391 |
|
|
|
1392 |
|
|
There is a Perl interface to TrollTech's Qt toolkit, but it does not |
1393 |
|
|
appear to be maintained. |
1394 |
|
|
|
1395 |
|
|
=end original |
1396 |
|
|
|
1397 |
|
|
TrollTech の Qt toolkit への Perl インターフェースはありますが、 |
1398 |
|
|
保守されていないようです。 |
1399 |
|
|
|
1400 |
|
|
=item Athena |
1401 |
|
|
|
1402 |
|
|
=begin original |
1403 |
|
|
|
1404 |
|
|
Sx is an interface to the Athena widget set which comes with X, but |
1405 |
|
|
again it appears not to be much used nowadays. |
1406 |
|
|
|
1407 |
|
|
=end original |
1408 |
|
|
|
1409 |
|
|
Sx は X に同梱されている Athena ウィジェットセットへのインターフェースですが、 |
1410 |
|
|
やはり最近ではほとんど使われていないようです。 |
1411 |
|
|
|
1412 |
|
|
=back |
1413 |
|
|
|
1414 |
|
|
=head2 How can I make my Perl program run faster? |
1415 |
|
|
|
1416 |
|
|
(私の Perl プログラムをもっと速くするには?) |
1417 |
|
|
|
1418 |
|
|
=begin original |
1419 |
|
|
|
1420 |
|
|
The best way to do this is to come up with a better algorithm. This |
1421 |
|
|
can often make a dramatic difference. Jon Bentley's book |
1422 |
|
|
I<Programming Pearls> (that's not a misspelling!) has some good tips |
1423 |
|
|
on optimization, too. Advice on benchmarking boils down to: benchmark |
1424 |
|
|
and profile to make sure you're optimizing the right part, look for |
1425 |
|
|
better algorithms instead of microtuning your code, and when all else |
1426 |
|
|
fails consider just buying faster hardware. You will probably want to |
1427 |
|
|
read the answer to the earlier question "How do I profile my Perl |
1428 |
|
|
programs?" if you haven't done so already. |
1429 |
|
|
|
1430 |
|
|
=end original |
1431 |
|
|
|
1432 |
|
|
その最善の方法とは、よりよいアルゴリズムを使うということです。 |
1433 |
|
|
ラクダ本の第八章にはあなたが感心をよせるかもしれない幾つかの効率的な |
1434 |
|
|
tips があります。 |
1435 |
|
|
Jon Bentleyの著作 "Programming Pearls" (ミススペルではありません!) |
1436 |
|
|
(邦訳「珠玉のプログラミング」)にも最適化に関するいくつかの Tips があります。 |
1437 |
|
|
ベンチマークとプロファイルによって、 |
1438 |
|
|
あなたのプログラムのどこに手を入れて最適化するのが正しいのかを |
1439 |
|
|
はっきりさせ、ちまちまと高速化を行うのではなくより良いアルゴリズムを |
1440 |
|
|
探す手掛かりになります。 |
1441 |
|
|
そして、どうしようもなくなったときには |
1442 |
|
|
いつ新しいハードウェアを買うかということを知る手掛かりともなります。 |
1443 |
|
|
まだ読んでいないなら、前述した "How do I profile my Perl programs?" という |
1444 |
|
|
質問の答えも読みたいと思うでしょう。 |
1445 |
|
|
|
1446 |
|
|
=begin original |
1447 |
|
|
|
1448 |
|
|
A different approach is to autoload seldom-used Perl code. See the |
1449 |
|
|
AutoSplit and AutoLoader modules in the standard distribution for |
1450 |
|
|
that. Or you could locate the bottleneck and think about writing just |
1451 |
|
|
that part in C, the way we used to take bottlenecks in C code and |
1452 |
|
|
write them in assembler. Similar to rewriting in C, modules that have |
1453 |
|
|
critical sections can be written in C (for instance, the PDL module |
1454 |
|
|
from CPAN). |
1455 |
|
|
|
1456 |
|
|
=end original |
1457 |
|
|
|
1458 |
|
|
別のアプローチには、時々使う Perl コードをオートローディングすると |
1459 |
|
|
いうものがあります。 |
1460 |
|
|
このために標準配布キットにある AutoSplit モジュールと |
1461 |
|
|
AutoLoader モジュールを参照してください。 |
1462 |
|
|
あるいは、ボトルネックとなっているところを特定し、その部分を |
1463 |
|
|
C で書くことを考えるかもしれません。 |
1464 |
|
|
ちょうど C で書かれたプログラムのボトルネックをアセンブラで |
1465 |
|
|
書くのと同じことです。 |
1466 |
|
|
C で書き直すという意味では、クリティカルセクションを持ったモジュールを |
1467 |
|
|
C で書き直すというのも同様です(例えば、CPAN にある |
1468 |
|
|
PDL モジュールがそうです)。 |
1469 |
|
|
|
1470 |
|
|
=begin original |
1471 |
|
|
|
1472 |
|
|
If you're currently linking your perl executable to a shared |
1473 |
|
|
I<libc.so>, you can often gain a 10-25% performance benefit by |
1474 |
|
|
rebuilding it to link with a static libc.a instead. This will make a |
1475 |
|
|
bigger perl executable, but your Perl programs (and programmers) may |
1476 |
|
|
thank you for it. See the F<INSTALL> file in the source distribution |
1477 |
|
|
for more information. |
1478 |
|
|
|
1479 |
|
|
=end original |
1480 |
|
|
|
1481 |
|
|
もしあなたが今、perl の実行ファイルと共有ライブラリ C<libc.so> を |
1482 |
|
|
リンクしているのであれば、スタティックに libc.a とリンクして perl を |
1483 |
|
|
再ビルドすることによって、しばしば 10-25% 性能を |
1484 |
|
|
向上させることが可能です。 |
1485 |
|
|
これは perl の実行ファイルを大きなものにしてしまいますが、 |
1486 |
|
|
あなたの Perl プログラム(とプログラマー)はスタティックリンクされたことを |
1487 |
|
|
感謝するでしょう。 |
1488 |
|
|
より詳しい情報は、ソース配布にある F<INSTALL> というファイルを |
1489 |
|
|
参照してください。 |
1490 |
|
|
|
1491 |
|
|
=begin original |
1492 |
|
|
|
1493 |
|
|
The undump program was an ancient attempt to speed up Perl program by |
1494 |
|
|
storing the already-compiled form to disk. This is no longer a viable |
1495 |
|
|
option, as it only worked on a few architectures, and wasn't a good |
1496 |
|
|
solution anyway. |
1497 |
|
|
|
1498 |
|
|
=end original |
1499 |
|
|
|
1500 |
|
|
undump プログラムは、コンパイル済みの形式でディスクに格納することで |
1501 |
|
|
Perlプログラムを高速化するのに古くは使われていました。 |
1502 |
|
|
これはほんの一部のアーキテクチャーでのみ働くものであって、 |
1503 |
|
|
最早価値ある選択肢ではなく、かつ、よい解決策ではありません。 |
1504 |
|
|
|
1505 |
|
|
=head2 How can I make my Perl program take less memory? |
1506 |
|
|
|
1507 |
|
|
(私の Perl プログラムのメモリ消費量を少なくするには?) |
1508 |
|
|
|
1509 |
|
|
=begin original |
1510 |
|
|
|
1511 |
|
|
When it comes to time-space tradeoffs, Perl nearly always prefers to |
1512 |
|
|
throw memory at a problem. Scalars in Perl use more memory than |
1513 |
|
|
strings in C, arrays take more than that, and hashes use even more. While |
1514 |
|
|
there's still a lot to be done, recent releases have been addressing |
1515 |
|
|
these issues. For example, as of 5.004, duplicate hash keys are |
1516 |
|
|
shared amongst all hashes using them, so require no reallocation. |
1517 |
|
|
|
1518 |
|
|
=end original |
1519 |
|
|
|
1520 |
|
|
時間と空間とを天秤に掛けたとき、Perl はほとんど常にメモリに関する |
1521 |
|
|
問題を放棄します。 |
1522 |
|
|
Perl におけるスカラーは C の文字列よりもメモリを消費し、 |
1523 |
|
|
配列も同様です。 |
1524 |
|
|
ハッシュは更にメモリを使います。 |
1525 |
|
|
まだ行うことは残ってはいるものの、最近のリリースではこの問題に |
1526 |
|
|
対処しています。 |
1527 |
|
|
たとえば 5.004 にあるように、重複したハッシュキーは全てのハッシュで |
1528 |
|
|
共有されます。 |
1529 |
|
|
このため、(そのハッシュキーの格納のための)再割り付けの必要はありません。 |
1530 |
|
|
|
1531 |
|
|
=begin original |
1532 |
|
|
|
1533 |
|
|
In some cases, using substr() or vec() to simulate arrays can be |
1534 |
|
|
highly beneficial. For example, an array of a thousand booleans will |
1535 |
|
|
take at least 20,000 bytes of space, but it can be turned into one |
1536 |
|
|
125-byte bit vector--a considerable memory savings. The standard |
1537 |
|
|
Tie::SubstrHash module can also help for certain types of data |
1538 |
|
|
structure. If you're working with specialist data structures |
1539 |
|
|
(matrices, for instance) modules that implement these in C may use |
1540 |
|
|
less memory than equivalent Perl modules. |
1541 |
|
|
|
1542 |
|
|
=end original |
1543 |
|
|
|
1544 |
|
|
substr() や vec() を使って配列をシミュレートすることで大幅に効率を |
1545 |
|
|
上げられることがあるでしょう。 |
1546 |
|
|
たとえば 1000 個のブール値を持った配列は、 |
1547 |
|
|
少なくとも 20000 バイトの空間を必要とします。 |
1548 |
|
|
しかし、これを 125 バイトのビットベクターに置き換えることができます-- |
1549 |
|
|
これで劇的にメモリを節約できます。 |
1550 |
|
|
標準の Tie::SubstrHash モジュールもデータ構造の幾つかの型に対する助けを |
1551 |
|
|
してくれるでしょう。 |
1552 |
|
|
あなたがデータ構造のスペシャリスト(例えば行列など)モジュールとともに |
1553 |
|
|
仕事をしようとしているのなら、 |
1554 |
|
|
C で実装されたモジュールは Perl で実装された等価なモジュールよりも |
1555 |
|
|
少ないメモリしか使わないでしょう。 |
1556 |
|
|
|
1557 |
|
|
=begin original |
1558 |
|
|
|
1559 |
|
|
Another thing to try is learning whether your Perl was compiled with |
1560 |
|
|
the system malloc or with Perl's builtin malloc. Whichever one it |
1561 |
|
|
is, try using the other one and see whether this makes a difference. |
1562 |
|
|
Information about malloc is in the F<INSTALL> file in the source |
1563 |
|
|
distribution. You can find out whether you are using perl's malloc by |
1564 |
|
|
typing C<perl -V:usemymalloc>. |
1565 |
|
|
|
1566 |
|
|
=end original |
1567 |
|
|
|
1568 |
|
|
試してみるべきもう一つの事柄は、あなたの使っている Perl がシステムの |
1569 |
|
|
malloc を使っているのか Perl 組み込みの malloc を使っているのかを |
1570 |
|
|
知ることです。 |
1571 |
|
|
いずれを使っているにしろ、別のものを使うようにしてみて |
1572 |
|
|
それによる差を確かめます。 |
1573 |
|
|
malloc に関する情報はソース配布にある F<INSTALL> というファイルにあります。 |
1574 |
|
|
C<perl -V:usemymalloc> とタイプすれば perl が使っている |
1575 |
|
|
malloc がどちらであるかを知ることができます。 |
1576 |
|
|
|
1577 |
|
|
=begin original |
1578 |
|
|
|
1579 |
|
|
Of course, the best way to save memory is to not do anything to waste |
1580 |
|
|
it in the first place. Good programming practices can go a long way |
1581 |
|
|
toward this: |
1582 |
|
|
|
1583 |
|
|
=end original |
1584 |
|
|
|
1585 |
|
|
もちろん、メモリを節約する一番の方法はまず無駄なことをしないことです。 |
1586 |
|
|
よいプログラミングプラクティスは以下のようなものを通じて得られています。 |
1587 |
|
|
|
1588 |
|
|
=over 4 |
1589 |
|
|
|
1590 |
|
|
=item * Don't slurp! |
1591 |
|
|
|
1592 |
|
|
(ファイル全体を読み込まない!) |
1593 |
|
|
|
1594 |
|
|
=begin original |
1595 |
|
|
|
1596 |
|
|
Don't read an entire file into memory if you can process it line |
1597 |
|
|
by line. Or more concretely, use a loop like this: |
1598 |
|
|
|
1599 |
|
|
=end original |
1600 |
|
|
|
1601 |
|
|
ファイルを行単位で処理するときにファイル全体をメモリに読み込んでは |
1602 |
|
|
いけません。 |
1603 |
|
|
より具体的には、以下のようなループを使います: |
1604 |
|
|
|
1605 |
|
|
# |
1606 |
|
|
# Good Idea |
1607 |
|
|
# |
1608 |
|
|
while (<FILE>) { |
1609 |
|
|
# ... |
1610 |
|
|
} |
1611 |
|
|
|
1612 |
|
|
=begin original |
1613 |
|
|
|
1614 |
|
|
instead of this: |
1615 |
|
|
|
1616 |
|
|
=end original |
1617 |
|
|
|
1618 |
|
|
以下のような方式はよくないです: |
1619 |
|
|
|
1620 |
|
|
# |
1621 |
|
|
# Bad Idea |
1622 |
|
|
# |
1623 |
|
|
@data = <FILE>; |
1624 |
|
|
foreach (@data) { |
1625 |
|
|
# ... |
1626 |
|
|
} |
1627 |
|
|
|
1628 |
|
|
=begin original |
1629 |
|
|
|
1630 |
|
|
When the files you're processing are small, it doesn't much matter which |
1631 |
|
|
way you do it, but it makes a huge difference when they start getting |
1632 |
|
|
larger. |
1633 |
|
|
|
1634 |
|
|
=end original |
1635 |
|
|
|
1636 |
|
|
処理するファイルサイズが小さいなら、どちらの方法をとっても大きな |
1637 |
|
|
違いはありません。 |
1638 |
|
|
しかし、ファイルが大きくなるにつれてその差は大きいものとなります。 |
1639 |
|
|
|
1640 |
|
|
=item * Use map and grep selectively |
1641 |
|
|
|
1642 |
|
|
(map と grep をうまく選んで使う) |
1643 |
|
|
|
1644 |
|
|
=begin original |
1645 |
|
|
|
1646 |
|
|
Remember that both map and grep expect a LIST argument, so doing this: |
1647 |
|
|
|
1648 |
|
|
=end original |
1649 |
|
|
|
1650 |
|
|
map と grep はどちらも LIST 引数を取るので、以下のようにすると: |
1651 |
|
|
|
1652 |
|
|
@wanted = grep {/pattern/} <FILE>; |
1653 |
|
|
|
1654 |
|
|
=begin original |
1655 |
|
|
|
1656 |
|
|
will cause the entire file to be slurped. For large files, it's better |
1657 |
|
|
to loop: |
1658 |
|
|
|
1659 |
|
|
=end original |
1660 |
|
|
|
1661 |
|
|
ファイル全体を読み込むことになります。 |
1662 |
|
|
大きなファイルでは以下のようにループしたほうがよいです: |
1663 |
|
|
|
1664 |
|
|
while (<FILE>) { |
1665 |
|
|
push(@wanted, $_) if /pattern/; |
1666 |
|
|
} |
1667 |
|
|
|
1668 |
|
|
=item * Avoid unnecessary quotes and stringification |
1669 |
|
|
|
1670 |
|
|
(不必要なクォートと文字列化を避ける) |
1671 |
|
|
|
1672 |
|
|
=begin original |
1673 |
|
|
|
1674 |
|
|
Don't quote large strings unless absolutely necessary: |
1675 |
|
|
|
1676 |
|
|
=end original |
1677 |
|
|
|
1678 |
|
|
本当に必要でないかぎりは大きな文字列をクォートしてはいけません。 |
1679 |
|
|
|
1680 |
|
|
my $copy = "$large_string"; |
1681 |
|
|
|
1682 |
|
|
=begin original |
1683 |
|
|
|
1684 |
|
|
makes 2 copies of $large_string (one for $copy and another for the |
1685 |
|
|
quotes), whereas |
1686 |
|
|
|
1687 |
|
|
=end original |
1688 |
|
|
|
1689 |
|
|
このように書くと、$large_string のコピーを二つ($copy とクォートと) |
1690 |
|
|
作ります。一方以下のようにすると: |
1691 |
|
|
|
1692 |
|
|
my $copy = $large_string; |
1693 |
|
|
|
1694 |
|
|
=begin original |
1695 |
|
|
|
1696 |
|
|
only makes one copy. |
1697 |
|
|
|
1698 |
|
|
=end original |
1699 |
|
|
|
1700 |
|
|
コピーは一つしか作られません。 |
1701 |
|
|
|
1702 |
|
|
=begin original |
1703 |
|
|
|
1704 |
|
|
Ditto for stringifying large arrays: |
1705 |
|
|
|
1706 |
|
|
=end original |
1707 |
|
|
|
1708 |
|
|
大きな配列の文字列化でも同じことが言えます: |
1709 |
|
|
|
1710 |
|
|
{ |
1711 |
|
|
local $, = "\n"; |
1712 |
|
|
print @big_array; |
1713 |
|
|
} |
1714 |
|
|
|
1715 |
|
|
=begin original |
1716 |
|
|
|
1717 |
|
|
is much more memory-efficient than either |
1718 |
|
|
|
1719 |
|
|
=end original |
1720 |
|
|
|
1721 |
|
|
これは以下のようなものよりメモリ効率がよいです: |
1722 |
|
|
|
1723 |
|
|
print join "\n", @big_array; |
1724 |
|
|
|
1725 |
|
|
=begin original |
1726 |
|
|
|
1727 |
|
|
or |
1728 |
|
|
|
1729 |
|
|
=end original |
1730 |
|
|
|
1731 |
|
|
または |
1732 |
|
|
|
1733 |
|
|
{ |
1734 |
|
|
local $" = "\n"; |
1735 |
|
|
print "@big_array"; |
1736 |
|
|
} |
1737 |
|
|
|
1738 |
|
|
=item * Pass by reference |
1739 |
|
|
|
1740 |
|
|
(リファレンスで渡す) |
1741 |
|
|
|
1742 |
|
|
=begin original |
1743 |
|
|
|
1744 |
|
|
Pass arrays and hashes by reference, not by value. For one thing, it's |
1745 |
|
|
the only way to pass multiple lists or hashes (or both) in a single |
1746 |
|
|
call/return. It also avoids creating a copy of all the contents. This |
1747 |
|
|
requires some judgement, however, because any changes will be propagated |
1748 |
|
|
back to the original data. If you really want to mangle (er, modify) a |
1749 |
|
|
copy, you'll have to sacrifice the memory needed to make one. |
1750 |
|
|
|
1751 |
|
|
=end original |
1752 |
|
|
|
1753 |
|
|
配列とハッシュは値ではなく、リファレンスで渡します。 |
1754 |
|
|
これは一つの呼び出し/返り値で複数のリストやハッシュ(やその両方)を |
1755 |
|
|
渡す唯一の方法です。 |
1756 |
|
|
また、これにより内容全てのコピーを作成しなくてすみます。 |
1757 |
|
|
しかし、これにはいくばくかの判断が必要です。なぜならあらゆる変更が |
1758 |
|
|
元のデータに伝播するからです。 |
1759 |
|
|
もし本当にコピーをいじりたい(修正したい)のなら、 |
1760 |
|
|
コピーを作るためのメモリを犠牲にする必要があります。 |
1761 |
|
|
|
1762 |
|
|
=item * Tie large variables to disk. |
1763 |
|
|
|
1764 |
|
|
(大きな変数をディスクに tie する) |
1765 |
|
|
|
1766 |
|
|
=begin original |
1767 |
|
|
|
1768 |
|
|
For "big" data stores (i.e. ones that exceed available memory) consider |
1769 |
|
|
using one of the DB modules to store it on disk instead of in RAM. This |
1770 |
|
|
will incur a penalty in access time, but that's probably better than |
1771 |
|
|
causing your hard disk to thrash due to massive swapping. |
1772 |
|
|
|
1773 |
|
|
=end original |
1774 |
|
|
|
1775 |
|
|
「大きな」データストア(利用可能なメモリ量を超えるようなもの)を |
1776 |
|
|
扱う時には RAM の代わりにディスクに保存するために DB モジュールの |
1777 |
|
|
どれかを使うことを考えてください。 |
1778 |
|
|
これはアクセス時間の低下を招きますが、おそらくは大量の |
1779 |
|
|
スワッピングによってハードディスクが激しく動くよりましです。 |
1780 |
|
|
|
1781 |
|
|
=back |
1782 |
|
|
|
1783 |
|
|
=head2 Is it safe to return a reference to local or lexical data? |
1784 |
|
|
|
1785 |
|
|
(ローカルやレキシカルなデータへのポインターを返すことは安全ですか?) |
1786 |
|
|
|
1787 |
|
|
=begin original |
1788 |
|
|
|
1789 |
|
|
Yes. Perl's garbage collection system takes care of this so |
1790 |
|
|
everything works out right. |
1791 |
|
|
|
1792 |
|
|
=end original |
1793 |
|
|
|
1794 |
|
|
はい。 |
1795 |
|
|
Perl のガベージコレクションシステムは全てがうまくいくように |
1796 |
|
|
考慮されています。 |
1797 |
|
|
|
1798 |
|
|
sub makeone { |
1799 |
|
|
my @a = ( 1 .. 10 ); |
1800 |
|
|
return \@a; |
1801 |
|
|
} |
1802 |
|
|
|
1803 |
|
|
for ( 1 .. 10 ) { |
1804 |
|
|
push @many, makeone(); |
1805 |
|
|
} |
1806 |
|
|
|
1807 |
|
|
print $many[4][5], "\n"; |
1808 |
|
|
|
1809 |
|
|
print "@many\n"; |
1810 |
|
|
|
1811 |
|
|
=head2 How can I free an array or hash so my program shrinks? |
1812 |
|
|
|
1813 |
|
|
(配列やハッシュを解放して私のプログラムを小さくするには?) |
1814 |
|
|
|
1815 |
|
|
=begin original |
1816 |
|
|
|
1817 |
|
|
(contributed by Michael Carman) |
1818 |
|
|
|
1819 |
|
|
=end original |
1820 |
|
|
|
1821 |
|
|
(Michael Carman によって寄贈されました) |
1822 |
|
|
|
1823 |
|
|
=begin original |
1824 |
|
|
|
1825 |
|
|
You usually can't. Memory allocated to lexicals (i.e. my() variables) |
1826 |
|
|
cannot be reclaimed or reused even if they go out of scope. It is |
1827 |
|
|
reserved in case the variables come back into scope. Memory allocated |
1828 |
|
|
to global variables can be reused (within your program) by using |
1829 |
|
|
undef() and/or delete(). |
1830 |
|
|
|
1831 |
|
|
=end original |
1832 |
|
|
|
1833 |
|
|
それは通常できません。 |
1834 |
|
|
レキシカル(例えば my() 変数) に割り当てられたメモリは、たとえスコープから |
1835 |
|
|
外れても再請求や再利用されません。 |
1836 |
|
|
これは変数がスコープ内に戻ってくる場合のために保存されます。 |
1837 |
|
|
グローバル変数に割り当てられたメモリは undef() や delete() を使うことで |
1838 |
|
|
(あなたのプログラム内で)再利用されます。 |
1839 |
|
|
|
1840 |
|
|
=begin original |
1841 |
|
|
|
1842 |
|
|
On most operating systems, memory allocated to a program can never be |
1843 |
|
|
returned to the system. That's why long-running programs sometimes re- |
1844 |
|
|
exec themselves. Some operating systems (notably, systems that use |
1845 |
|
|
mmap(2) for allocating large chunks of memory) can reclaim memory that |
1846 |
|
|
is no longer used, but on such systems, perl must be configured and |
1847 |
|
|
compiled to use the OS's malloc, not perl's. |
1848 |
|
|
|
1849 |
|
|
=end original |
1850 |
|
|
|
1851 |
|
|
ほとんどのシステムでは、プログラムのために |
1852 |
|
|
割り付けたメモリは、決してシステムに返されることはありません。 |
1853 |
|
|
これは、長期間動作しているプログラムが時々自分自身を |
1854 |
|
|
再起動する理由でもあります。 |
1855 |
|
|
一部のオペレーティングシステム(特に大きなメモリの塊を |
1856 |
|
|
割り付けるときに mmap(2) を使うシステム)では、 |
1857 |
|
|
最早使われていないメモリの塊を回収できますが、 |
1858 |
|
|
そのようなシステムでは、perl を perl 自身ではなく OS の |
1859 |
|
|
malloc を使うように設定し、コンパイルしなければなりません。 |
1860 |
|
|
|
1861 |
|
|
=begin original |
1862 |
|
|
|
1863 |
|
|
In general, memory allocation and de-allocation isn't something you can |
1864 |
|
|
or should be worrying about much in Perl. |
1865 |
|
|
|
1866 |
|
|
=end original |
1867 |
|
|
|
1868 |
|
|
一般的に、メモリの確保と解放の問題は Perl においてはあまり気にする必要がある |
1869 |
|
|
問題ではありません。 |
1870 |
|
|
|
1871 |
|
|
=begin original |
1872 |
|
|
|
1873 |
|
|
See also "How can I make my Perl program take less memory?" |
1874 |
|
|
|
1875 |
|
|
=end original |
1876 |
|
|
|
1877 |
|
|
"How can I make my Perl program take less memory?" も参照してください。 |
1878 |
|
|
|
1879 |
|
|
=head2 How can I make my CGI script more efficient? |
1880 |
|
|
|
1881 |
|
|
(私の CGI スクリプトをもっと効率よくするには?) |
1882 |
|
|
|
1883 |
|
|
=begin original |
1884 |
|
|
|
1885 |
|
|
Beyond the normal measures described to make general Perl programs |
1886 |
|
|
faster or smaller, a CGI program has additional issues. It may be run |
1887 |
|
|
several times per second. Given that each time it runs it will need |
1888 |
|
|
to be re-compiled and will often allocate a megabyte or more of system |
1889 |
|
|
memory, this can be a killer. Compiling into C B<isn't going to help |
1890 |
|
|
you> because the process start-up overhead is where the bottleneck is. |
1891 |
|
|
|
1892 |
|
|
=end original |
1893 |
|
|
|
1894 |
|
|
普通の Perl プログラムを速くしたり小さくしたりするための基準とは別に、 |
1895 |
|
|
CGI プログラムには更に別の基準があります。 |
1896 |
|
|
CGI プログラムは一秒に数回実行される可能性があります。 |
1897 |
|
|
実行する度毎にスクリプトの再コンパイルとシステムメモリを |
1898 |
|
|
一メガバイト以上割りつけることが必要となります。 |
1899 |
|
|
これは問題点となり得ます。 |
1900 |
|
|
C へコンパイルすることは B<助けにはなりません>。 |
1901 |
|
|
なぜなら、プロセスのスタートアップ時のオーバーヘッドが |
1902 |
|
|
ボトルネックだからです。 |
1903 |
|
|
|
1904 |
|
|
=begin original |
1905 |
|
|
|
1906 |
|
|
There are two popular ways to avoid this overhead. One solution |
1907 |
|
|
involves running the Apache HTTP server (available from |
1908 |
|
|
http://www.apache.org/ ) with either of the mod_perl or mod_fastcgi |
1909 |
|
|
plugin modules. |
1910 |
|
|
|
1911 |
|
|
=end original |
1912 |
|
|
|
1913 |
|
|
このオーバーヘッドを避けるためのポピュラーな手段が二つあります。 |
1914 |
|
|
解決策の一つは Apache HTTP サーバー(http://www.apache.org/ から入手可能)に |
1915 |
|
|
mod_perl か mod_fastcgi のいずれかのプラグインモジュールを |
1916 |
|
|
取り込ませて実行させるというものです。 |
1917 |
|
|
|
1918 |
|
|
=begin original |
1919 |
|
|
|
1920 |
|
|
With mod_perl and the Apache::Registry module (distributed with |
1921 |
|
|
mod_perl), httpd will run with an embedded Perl interpreter which |
1922 |
|
|
pre-compiles your script and then executes it within the same address |
1923 |
|
|
space without forking. The Apache extension also gives Perl access to |
1924 |
|
|
the internal server API, so modules written in Perl can do just about |
1925 |
|
|
anything a module written in C can. For more on mod_perl, see |
1926 |
|
|
http://perl.apache.org/ |
1927 |
|
|
|
1928 |
|
|
=end original |
1929 |
|
|
|
1930 |
|
|
mod_perl と Apache::Registry モジュール(mod_perl と一緒に配布されて |
1931 |
|
|
います)と組み合わせることで、httpd は組み込みの Perl インタプリタと |
1932 |
|
|
共に実行させるようになります。 |
1933 |
|
|
これで、あなたのスクリプトは事前にコンパイルされ、 |
1934 |
|
|
それを fork 抜きで同じアドレス空間で実行されるようになります。 |
1935 |
|
|
Apatche エクステンションはまた、 |
1936 |
|
|
Perl に内部サーバー API をアクセスすることを許可するので、 |
1937 |
|
|
Perl で記述されたモジュールは C で書かれたモジュールができることはなんでも |
1938 |
|
|
できるようになります。 |
1939 |
|
|
mod_perl に関する詳細は http://perl.apache.org/ を参照してください。 |
1940 |
|
|
|
1941 |
|
|
=begin original |
1942 |
|
|
|
1943 |
|
|
With the FCGI module (from CPAN) and the mod_fastcgi |
1944 |
|
|
module (available from http://www.fastcgi.com/ ) each of your Perl |
1945 |
|
|
programs becomes a permanent CGI daemon process. |
1946 |
|
|
|
1947 |
|
|
=end original |
1948 |
|
|
|
1949 |
|
|
FCGI モジュール(CPAN にあります)と |
1950 |
|
|
mod_fastcgi モジュール(http://www.fastcgi.com で入手できます)は |
1951 |
|
|
あなたの Perl プログラムのそれぞれを永続的 CGI デーモンプロセスにします。 |
1952 |
|
|
|
1953 |
|
|
=begin original |
1954 |
|
|
|
1955 |
|
|
Both of these solutions can have far-reaching effects on your system |
1956 |
|
|
and on the way you write your CGI programs, so investigate them with |
1957 |
|
|
care. |
1958 |
|
|
|
1959 |
|
|
=end original |
1960 |
|
|
|
1961 |
|
|
これらの解決策は両方ともあなたの使うシステムで効果がない可能性があり、 |
1962 |
|
|
また、あなたが書いた CGI プログラムに依存する方法なので、 |
1963 |
|
|
注意して検査してください。 |
1964 |
|
|
|
1965 |
|
|
=begin original |
1966 |
|
|
|
1967 |
|
|
See http://www.cpan.org/modules/by-category/15_World_Wide_Web_HTML_HTTP_CGI/ . |
1968 |
|
|
|
1969 |
|
|
=end original |
1970 |
|
|
|
1971 |
|
|
http://www.cpan.org/modules/by-category/15_World_Wide_Web_HTML_HTTP_CGI/ を |
1972 |
|
|
参照してください。 |
1973 |
|
|
|
1974 |
|
|
=head2 How can I hide the source for my Perl program? |
1975 |
|
|
|
1976 |
|
|
(私の Perl プログラムのソースを隠すには?) |
1977 |
|
|
|
1978 |
|
|
=begin original |
1979 |
|
|
|
1980 |
|
|
Delete it. :-) Seriously, there are a number of (mostly |
1981 |
|
|
unsatisfactory) solutions with varying levels of "security". |
1982 |
|
|
|
1983 |
|
|
=end original |
1984 |
|
|
|
1985 |
|
|
削除しましょう :-) まじめな話、様々な「セキュリティ」レベルを持った |
1986 |
|
|
幾つかの解決策があります(ほとんどは満足行くものではないでしょう)。 |
1987 |
|
|
|
1988 |
|
|
=begin original |
1989 |
|
|
|
1990 |
|
|
First of all, however, you I<can't> take away read permission, because |
1991 |
|
|
the source code has to be readable in order to be compiled and |
1992 |
|
|
interpreted. (That doesn't mean that a CGI script's source is |
1993 |
|
|
readable by people on the web, though--only by people with access to |
1994 |
|
|
the filesystem.) So you have to leave the permissions at the socially |
1995 |
|
|
friendly 0755 level. |
1996 |
|
|
|
1997 |
|
|
=end original |
1998 |
|
|
|
1999 |
|
|
しかしながら、まず最初に、あなたは読み取り権限(read permission)を |
2000 |
|
|
落とすことはできません。 |
2001 |
|
|
なぜなら、スクリプトのソースコードはコンパイルと解釈のために |
2002 |
|
|
読み取り可能でなければならない |
2003 |
|
|
からです(これは CGI スクリプトのソースコードが web 上で、 |
2004 |
|
|
読み取り可能であることとは違います-- |
2005 |
|
|
ファイルシステムに対してアクセスできる人だけが読み取り可能です)。 |
2006 |
|
|
ですから、権限の設定を少なくとも socially friendly な 0755 の |
2007 |
|
|
レベルにしておく必要があります。 |
2008 |
|
|
|
2009 |
|
|
=begin original |
2010 |
|
|
|
2011 |
|
|
Some people regard this as a security problem. If your program does |
2012 |
|
|
insecure things and relies on people not knowing how to exploit those |
2013 |
|
|
insecurities, it is not secure. It is often possible for someone to |
2014 |
|
|
determine the insecure things and exploit them without viewing the |
2015 |
|
|
source. Security through obscurity, the name for hiding your bugs |
2016 |
|
|
instead of fixing them, is little security indeed. |
2017 |
|
|
|
2018 |
|
|
=end original |
2019 |
|
|
|
2020 |
|
|
中にはこれをセキュリティ上の問題であると考えている人もいます。 |
2021 |
|
|
あなたのプログラムが安全でないことを行った場合、 |
2022 |
|
|
そして、人々がそのような安全でないことを暴露する方法を知らないことに |
2023 |
|
|
頼っているのなら、安全ではないのです。 |
2024 |
|
|
誰かが、安全でないことを見つけだすこととソースを見ることなしにそれを |
2025 |
|
|
暴露することはしばしば可能となるのです。 |
2026 |
|
|
セキュリティバグを直すのではなくてそのバグを隠すといった、 |
2027 |
|
|
知られていないことに頼るセキュリティ(security through obscurity)は |
2028 |
|
|
小さなセキュリティの傷です。 |
2029 |
|
|
|
2030 |
|
|
=begin original |
2031 |
|
|
|
2032 |
|
|
You can try using encryption via source filters (Starting from Perl |
2033 |
|
|
5.8 the Filter::Simple and Filter::Util::Call modules are included in |
2034 |
|
|
the standard distribution), but any decent programmer will be able to |
2035 |
|
|
decrypt it. You can try using the byte code compiler and interpreter |
2036 |
|
|
described later in L<perlfaq3>, but the curious might still be able to |
2037 |
|
|
de-compile it. You can try using the native-code compiler described |
2038 |
|
|
later, but crackers might be able to disassemble it. These pose |
2039 |
|
|
varying degrees of difficulty to people wanting to get at your code, |
2040 |
|
|
but none can definitively conceal it (true of every language, not just |
2041 |
|
|
Perl). |
2042 |
|
|
|
2043 |
|
|
=end original |
2044 |
|
|
|
2045 |
|
|
ソースフィルタ(Perl 5.8 からは Filter::Simple と Filter::Util::Call は |
2046 |
|
|
標準配布物に含まれています)を使った暗号化を試すこともできます。 |
2047 |
|
|
しかし、悪意在るプログラマーはそれを復号化できるかもしれません。 |
2048 |
|
|
あなたは L<perlfaq3> で後述するバイトコードコンパイラとインタプリタを |
2049 |
|
|
使うことを試せるかもしれませんが、 |
2050 |
|
|
探りたがりの人はそれを逆コンパイルできるかもしれません。 |
2051 |
|
|
後述するネイティブコードコンパイラを試すこともできますが、 |
2052 |
|
|
クラッカーはそれを逆アセンブルできるかもしれません。 |
2053 |
|
|
これらの手段は、あなたのプログラムを手に入れようとする人達に様々な困難を |
2054 |
|
|
もたらしますが、誰もそれを決定的に防ぐ障壁にすることはできないのです |
2055 |
|
|
(Perl のみに限らず、あらゆる言語で真となります)。 |
2056 |
|
|
|
2057 |
|
|
=begin original |
2058 |
|
|
|
2059 |
|
|
It is very easy to recover the source of Perl programs. You simply |
2060 |
|
|
feed the program to the perl interpreter and use the modules in |
2061 |
|
|
the B:: hierarchy. The B::Deparse module should be able to |
2062 |
|
|
defeat most attempts to hide source. Again, this is not |
2063 |
|
|
unique to Perl. |
2064 |
|
|
|
2065 |
|
|
=end original |
2066 |
|
|
|
2067 |
|
|
Perl プログラムのソースを取り出すのはとても簡単です。 |
2068 |
|
|
プログラムを perl インタプリタに渡して B:: 階層のモジュールを |
2069 |
|
|
使うだけです。 |
2070 |
|
|
B::Deparse モジュールはソースを隠そうとするほとんどの試みを |
2071 |
|
|
打ち破るはずです。 |
2072 |
|
|
繰り返しますが、これは Perl に限ったことではありません。 |
2073 |
|
|
|
2074 |
|
|
=begin original |
2075 |
|
|
|
2076 |
|
|
If you're concerned about people profiting from your code, then the |
2077 |
|
|
bottom line is that nothing but a restrictive license will give you |
2078 |
|
|
legal security. License your software and pepper it with threatening |
2079 |
|
|
statements like "This is unpublished proprietary software of XYZ Corp. |
2080 |
|
|
Your access to it does not give you permission to use it blah blah |
2081 |
|
|
blah." We are not lawyers, of course, so you should see a lawyer if |
2082 |
|
|
you want to be sure your license's wording will stand up in court. |
2083 |
|
|
|
2084 |
|
|
=end original |
2085 |
|
|
|
2086 |
|
|
あなたが、誰かがあなたのプログラムを元になにか利益を |
2087 |
|
|
得るのではないかということを考えているのなら、 |
2088 |
|
|
プログラムの最後の行を制限付きライセンスとすれば、 |
2089 |
|
|
あなたに法的な安全性 (legal security)をもたらすでしょう。 |
2090 |
|
|
あなたのソフトウェアをライセンスし、 |
2091 |
|
|
“This is unpublished proprietary software of XYZ Corp. |
2092 |
|
|
Your access to it does not give you permission to use it blah blah |
2093 |
|
|
blah.” |
2094 |
|
|
(本ソフトウェアは、XYZ コーポレイションにより作成された非公開の |
2095 |
|
|
独占的ソフトウェアです。 |
2096 |
|
|
あなたがこれにアクセスすることは許されていません、云々) |
2097 |
|
|
のような文章で味付けします。 |
2098 |
|
|
もちろん私たちは弁護士ではありませんから、 |
2099 |
|
|
あなたが確実に自分のライセンスが有効なものになるようにしたいのなら、 |
2100 |
|
|
弁護士に会っておくべきでしょう。 |
2101 |
|
|
|
2102 |
|
|
=head2 How can I compile my Perl program into byte code or C? |
2103 |
|
|
|
2104 |
|
|
(私の Perl プログラムをバイトコードや C へコンパイルするには?) |
2105 |
|
|
|
2106 |
|
|
=begin original |
2107 |
|
|
|
2108 |
|
|
(contributed by brian d foy) |
2109 |
|
|
|
2110 |
|
|
=end original |
2111 |
|
|
|
2112 |
|
|
(brian d foy によって寄贈されました) |
2113 |
|
|
|
2114 |
|
|
=begin original |
2115 |
|
|
|
2116 |
|
|
In general, you can't do this. There are some things that may work |
2117 |
|
|
for your situation though. People usually ask this question |
2118 |
|
|
because they want to distribute their works without giving away |
2119 |
|
|
the source code, and most solutions trade disk space for convenience. |
2120 |
|
|
You probably won't see much of a speed increase either, since most |
2121 |
|
|
solutions simply bundle a Perl interpreter in the final product |
2122 |
|
|
(but see L<How can I make my Perl program run faster?>). |
2123 |
|
|
|
2124 |
|
|
=end original |
2125 |
|
|
|
2126 |
|
|
一般的には、それはできません。 |
2127 |
|
|
しかし、状況によっては可能な場合もあります。 |
2128 |
|
|
人々は普通、ソースを提供することなく成果を配布したいためにこの質問をします; |
2129 |
|
|
そしてほとんどの解決法は便利さのためにディスクスペースを犠牲にします。 |
2130 |
|
|
ほとんどの解決法は単に最終製品に Perl インタプリタを同梱しているので、 |
2131 |
|
|
どれを使ってもおそらく大して速度は向上しないでしょう |
2132 |
|
|
(しかし L<How can I make my Perl program run faster?> を参照してください)。 |
2133 |
|
|
|
2134 |
|
|
=begin original |
2135 |
|
|
|
2136 |
|
|
The Perl Archive Toolkit ( http://par.perl.org/ ) is Perl's |
2137 |
|
|
analog to Java's JAR. It's freely available and on CPAN ( |
2138 |
|
|
http://search.cpan.org/dist/PAR/ ). |
2139 |
|
|
|
2140 |
|
|
=end original |
2141 |
|
|
|
2142 |
|
|
The Perl Archive Toolkit ( http://par.perl.org/ ) は Java における |
2143 |
|
|
JAR のような Perl 版の類似物です。 |
2144 |
|
|
自由に利用可能で、CPAN にあります ( http://search.cpan.org/dist/PAR/ )。 |
2145 |
|
|
|
2146 |
|
|
=begin original |
2147 |
|
|
|
2148 |
|
|
There are also some commercial products that may work for you, although |
2149 |
|
|
you have to buy a license for them. |
2150 |
|
|
|
2151 |
|
|
=end original |
2152 |
|
|
|
2153 |
|
|
役に立つかもしれないいくつかの商用製品もありますが、それらのライセンスを |
2154 |
|
|
購入する必要があります。 |
2155 |
|
|
|
2156 |
|
|
=begin original |
2157 |
|
|
|
2158 |
|
|
The Perl Dev Kit ( http://www.activestate.com/Products/Perl_Dev_Kit/ ) |
2159 |
|
|
from ActiveState can "Turn your Perl programs into ready-to-run |
2160 |
|
|
executables for HP-UX, Linux, Solaris and Windows." |
2161 |
|
|
|
2162 |
|
|
=end original |
2163 |
|
|
|
2164 |
|
|
ActiveState の The Perl Dev Kit |
2165 |
|
|
( http://www.activestate.com/Products/Perl_Dev_Kit/ ) は |
2166 |
|
|
「あなたの Perl プログラムを HP-UX, Linux, Solaris, Windows 用の実行 |
2167 |
|
|
ファイルに変換します。」 |
2168 |
|
|
|
2169 |
|
|
=begin original |
2170 |
|
|
|
2171 |
|
|
Perl2Exe ( http://www.indigostar.com/perl2exe.htm ) is a command line |
2172 |
|
|
program for converting perl scripts to executable files. It targets both |
2173 |
|
|
Windows and Unix platforms. |
2174 |
|
|
|
2175 |
|
|
=end original |
2176 |
|
|
|
2177 |
|
|
Perl2Exe ( http://www.indigostar.com/perl2exe.htm ) は perl スクリプトを |
2178 |
|
|
実行可能ファイルに変換するコマンドラインプログラムです。 |
2179 |
|
|
これは Windows と Unix プラットフォームの両方を対象としています。 |
2180 |
|
|
|
2181 |
|
|
=head2 How can I get C<#!perl> to work on [MS-DOS,NT,...]? |
2182 |
|
|
|
2183 |
|
|
(MS-DOS, NT, etc で '#!perl' が動作するようにするには?) |
2184 |
|
|
|
2185 |
|
|
=begin original |
2186 |
|
|
|
2187 |
|
|
For OS/2 just use |
2188 |
|
|
|
2189 |
|
|
=end original |
2190 |
|
|
|
2191 |
|
|
OS/2 では単に: |
2192 |
|
|
|
2193 |
|
|
extproc perl -S -your_switches |
2194 |
|
|
|
2195 |
|
|
=begin original |
2196 |
|
|
|
2197 |
|
|
as the first line in C<*.cmd> file (C<-S> due to a bug in cmd.exe's |
2198 |
|
|
"extproc" handling). For DOS one should first invent a corresponding |
2199 |
|
|
batch file and codify it in C<ALTERNATE_SHEBANG> (see the |
2200 |
|
|
F<dosish.h> file in the source distribution for more information). |
2201 |
|
|
|
2202 |
|
|
=end original |
2203 |
|
|
|
2204 |
|
|
C<*.cmd> ファイルの先頭をこのようにするだけです(C<-S> は、 |
2205 |
|
|
cmd.exe の "extproc" に関するバグのためです)。 |
2206 |
|
|
DOS の場合は、適切なバッチファイルを作って C<ALTERNATE_SHEBANG> を |
2207 |
|
|
行うべきでしょう(詳細は、ソース配布キットにある F<dosish.h> という |
2208 |
|
|
ファイルを参照してください)。 |
2209 |
|
|
|
2210 |
|
|
=begin original |
2211 |
|
|
|
2212 |
|
|
The Win95/NT installation, when using the ActiveState port of Perl, |
2213 |
|
|
will modify the Registry to associate the C<.pl> extension with the |
2214 |
|
|
perl interpreter. If you install another port, perhaps even building |
2215 |
|
|
your own Win95/NT Perl from the standard sources by using a Windows port |
2216 |
|
|
of gcc (e.g., with cygwin or mingw32), then you'll have to modify |
2217 |
|
|
the Registry yourself. In addition to associating C<.pl> with the |
2218 |
|
|
interpreter, NT people can use: C<SET PATHEXT=%PATHEXT%;.PL> to let them |
2219 |
|
|
run the program C<install-linux.pl> merely by typing C<install-linux>. |
2220 |
|
|
|
2221 |
|
|
=end original |
2222 |
|
|
|
2223 |
|
|
Windows 95 や Windows NT で ActiveState の移植した Perl を使うのなら、 |
2224 |
|
|
これは C<.pl> という拡張子を perl インタプリタに関連づけるように |
2225 |
|
|
レジストリを変更します。 |
2226 |
|
|
その他の移植になる perl を使うか、あるいはあなた自身が Windows に |
2227 |
|
|
移植された gcc(cygwin や mingw)を使って標準ソースから Perl を |
2228 |
|
|
ビルドするというのであれば自分自身でレジストリを変更する必要があるでしょう。 |
2229 |
|
|
C<.pl> とインタプリタを関連づけることによって、NT を使っている |
2230 |
|
|
人は C<install-linux.pl> を C<install-linux> のように起動することが |
2231 |
|
|
可能です。 |
2232 |
|
|
NT では C<SET PATHEXT=%PATHEXT%;.PL> のようにします。 |
2233 |
|
|
|
2234 |
|
|
=begin original |
2235 |
|
|
|
2236 |
|
|
Under "Classic" MacOS, a perl program will have the appropriate Creator and |
2237 |
|
|
Type, so that double-clicking them will invoke the MacPerl application. |
2238 |
|
|
Under Mac OS X, clickable apps can be made from any C<#!> script using Wil |
2239 |
|
|
Sanchez' DropScript utility: http://www.wsanchez.net/software/ . |
2240 |
|
|
|
2241 |
|
|
=end original |
2242 |
|
|
|
2243 |
|
|
"Classic" MacOS では、perl のプログラムは適切な Creator と Type とを |
2244 |
|
|
持っているでしょうから、ダブルクリックするだけで |
2245 |
|
|
MacPerl アプリケーションが起動するでしょう。 |
2246 |
|
|
Mac OS X では、クリックできるアプリケーションは Wil Sanchez の DropScript |
2247 |
|
|
utility: http://www.wsanchez.net/software/ を使って任意の C<#!> |
2248 |
|
|
スクリプトから作成できます。 |
2249 |
|
|
|
2250 |
|
|
=begin original |
2251 |
|
|
|
2252 |
|
|
I<IMPORTANT!>: Whatever you do, PLEASE don't get frustrated, and just |
2253 |
|
|
throw the perl interpreter into your cgi-bin directory, in order to |
2254 |
|
|
get your programs working for a web server. This is an EXTREMELY big |
2255 |
|
|
security risk. Take the time to figure out how to do it correctly. |
2256 |
|
|
|
2257 |
|
|
=end original |
2258 |
|
|
|
2259 |
|
|
B<重要!>: あなたが何をするにしても、どうか不満を感じないでください。 |
2260 |
|
|
そして、あなたのプログラムが web サーバのために動作するようにさせるために |
2261 |
|
|
perl インタプリタを cgi-bin ディレクトリに放り込むようなことは |
2262 |
|
|
しないでください。 |
2263 |
|
|
これは B<非常に> 大きなセキュリティ上のリスクとなります。 |
2264 |
|
|
正しく動作させるための方法を考えるための時間を取ってください。 |
2265 |
|
|
|
2266 |
|
|
=head2 Can I write useful Perl programs on the command line? |
2267 |
|
|
|
2268 |
|
|
(コマンドライン上で便利な Perl プログラムを書けますか?) |
2269 |
|
|
|
2270 |
|
|
=begin original |
2271 |
|
|
|
2272 |
|
|
Yes. Read L<perlrun> for more information. Some examples follow. |
2273 |
|
|
(These assume standard Unix shell quoting rules.) |
2274 |
|
|
|
2275 |
|
|
=end original |
2276 |
|
|
|
2277 |
|
|
はい。 |
2278 |
|
|
詳しくはL<perlrun>を読んでください。 |
2279 |
|
|
幾つかのサンプルを以下に挙げておきます(ここでは標準のUNIX シェル引用規則に |
2280 |
|
|
従っていると仮定します)。 |
2281 |
|
|
|
2282 |
|
|
# sum first and last fields |
2283 |
|
|
perl -lane 'print $F[0] + $F[-1]' * |
2284 |
|
|
|
2285 |
|
|
# identify text files |
2286 |
|
|
perl -le 'for(@ARGV) {print if -f && -T _}' * |
2287 |
|
|
|
2288 |
|
|
# remove (most) comments from C program |
2289 |
|
|
perl -0777 -pe 's{/\*.*?\*/}{}gs' foo.c |
2290 |
|
|
|
2291 |
|
|
# make file a month younger than today, defeating reaper daemons |
2292 |
|
|
perl -e '$X=24*60*60; utime(time(),time() + 30 * $X,@ARGV)' * |
2293 |
|
|
|
2294 |
|
|
# find first unused uid |
2295 |
|
|
perl -le '$i++ while getpwuid($i); print $i' |
2296 |
|
|
|
2297 |
|
|
# display reasonable manpath |
2298 |
|
|
echo $PATH | perl -nl -072 -e ' |
2299 |
|
|
s![^/+]*$!man!&&-d&&!$s{$_}++&&push@m,$_;END{print"@m"}' |
2300 |
|
|
|
2301 |
|
|
=begin original |
2302 |
|
|
|
2303 |
|
|
OK, the last one was actually an Obfuscated Perl Contest entry. :-) |
2304 |
|
|
|
2305 |
|
|
=end original |
2306 |
|
|
|
2307 |
|
|
そう、最後のは Obfuscated Perl コンテストにエントリーされてましたね :-) |
2308 |
|
|
|
2309 |
|
|
=head2 Why don't Perl one-liners work on my DOS/Mac/VMS system? |
2310 |
|
|
|
2311 |
|
|
(なぜ私の DOS/Mac/VMS システムでは一行野郎は動かないのでしょうか?) |
2312 |
|
|
|
2313 |
|
|
=begin original |
2314 |
|
|
|
2315 |
|
|
The problem is usually that the command interpreters on those systems |
2316 |
|
|
have rather different ideas about quoting than the Unix shells under |
2317 |
|
|
which the one-liners were created. On some systems, you may have to |
2318 |
|
|
change single-quotes to double ones, which you must I<NOT> do on Unix |
2319 |
|
|
or Plan9 systems. You might also have to change a single % to a %%. |
2320 |
|
|
|
2321 |
|
|
=end original |
2322 |
|
|
|
2323 |
|
|
この問題は、そういったシステムのコマンドインタプリタが、 |
2324 |
|
|
一行野郎が作られた環境であるUNIXのシェルの引用規則とは異なるこということです。 |
2325 |
|
|
一部のシステムでは、シングルクォートをダブルクォートに変更する必要が |
2326 |
|
|
あるかもしれません(これは UNIX や Plan9 といったシステムでは |
2327 |
|
|
B<してはいけません>)。 |
2328 |
|
|
同様に、%を%%に変更する必要もあるかもしれません。 |
2329 |
|
|
|
2330 |
|
|
=begin original |
2331 |
|
|
|
2332 |
|
|
For example: |
2333 |
|
|
|
2334 |
|
|
=end original |
2335 |
|
|
|
2336 |
|
|
例を挙げましょう: |
2337 |
|
|
|
2338 |
|
|
# Unix (including Mac OS X) |
2339 |
|
|
perl -e 'print "Hello world\n"' |
2340 |
|
|
|
2341 |
|
|
# DOS, etc. |
2342 |
|
|
perl -e "print \"Hello world\n\"" |
2343 |
|
|
|
2344 |
|
|
# Mac Classic |
2345 |
|
|
print "Hello world\n" |
2346 |
|
|
(then Run "Myscript" or Shift-Command-R) |
2347 |
|
|
|
2348 |
|
|
# MPW |
2349 |
|
|
perl -e 'print "Hello world\n"' |
2350 |
|
|
|
2351 |
|
|
# VMS |
2352 |
|
|
perl -e "print ""Hello world\n""" |
2353 |
|
|
|
2354 |
|
|
=begin original |
2355 |
|
|
|
2356 |
|
|
The problem is that none of these examples are reliable: they depend on the |
2357 |
|
|
command interpreter. Under Unix, the first two often work. Under DOS, |
2358 |
|
|
it's entirely possible that neither works. If 4DOS was the command shell, |
2359 |
|
|
you'd probably have better luck like this: |
2360 |
|
|
|
2361 |
|
|
=end original |
2362 |
|
|
|
2363 |
|
|
問題は、これらの例の中に信頼できるものがないということです: |
2364 |
|
|
コマンドインタープリタに依存します。 |
2365 |
|
|
UNIX では、最初の二つはほとんどの場合動作するでしょう。 |
2366 |
|
|
DOS では、どれも働かないかもしれません。 |
2367 |
|
|
4DOS をコマンドシェルとしているのなら、以下のようにするのがよいと思います: |
2368 |
|
|
|
2369 |
|
|
perl -e "print <Ctrl-x>"Hello world\n<Ctrl-x>"" |
2370 |
|
|
|
2371 |
|
|
=begin original |
2372 |
|
|
|
2373 |
|
|
Under the Mac, it depends which environment you are using. The MacPerl |
2374 |
|
|
shell, or MPW, is much like Unix shells in its support for several |
2375 |
|
|
quoting variants, except that it makes free use of the Mac's non-ASCII |
2376 |
|
|
characters as control characters. |
2377 |
|
|
|
2378 |
|
|
=end original |
2379 |
|
|
|
2380 |
|
|
Mac では、あなたが使っている環境に依存します。 |
2381 |
|
|
MacPerl シェルや MPW は、制御キャラクターのような Mac の |
2382 |
|
|
非 ASCII キャラクターが自由に使えるという点を除いて、 |
2383 |
|
|
UNIX シェルのように数種類の引用規則をサポートします。 |
2384 |
|
|
|
2385 |
|
|
=begin original |
2386 |
|
|
|
2387 |
|
|
Using qq(), q(), and qx(), instead of "double quotes", 'single |
2388 |
|
|
quotes', and `backticks`, may make one-liners easier to write. |
2389 |
|
|
|
2390 |
|
|
=end original |
2391 |
|
|
|
2392 |
|
|
ダブルクォート(")、シングルクォート(')、バッククォート(`)の |
2393 |
|
|
代わりに qq(), q(), qx() をそれぞれ使います。 |
2394 |
|
|
これによって一行野郎を書くことが簡単になるかもしれません。 |
2395 |
|
|
|
2396 |
|
|
=begin original |
2397 |
|
|
|
2398 |
|
|
There is no general solution to all of this. It is a mess. |
2399 |
|
|
|
2400 |
|
|
=end original |
2401 |
|
|
|
2402 |
|
|
この件全てに関する一般的な解決策はありません。 |
2403 |
|
|
ごちゃごちゃです。 |
2404 |
|
|
|
2405 |
|
|
=begin original |
2406 |
|
|
|
2407 |
|
|
[Some of this answer was contributed by Kenneth Albanowski.] |
2408 |
|
|
|
2409 |
|
|
=end original |
2410 |
|
|
|
2411 |
|
|
[この回答の一部はKenneth Albanowskiから寄せられました] |
2412 |
|
|
|
2413 |
|
|
=head2 Where can I learn about CGI or Web programming in Perl? |
2414 |
|
|
|
2415 |
|
|
(Perl による CGI や Web プログラミングについてどこで学べますか?) |
2416 |
|
|
|
2417 |
|
|
=begin original |
2418 |
|
|
|
2419 |
|
|
For modules, get the CGI or LWP modules from CPAN. For textbooks, |
2420 |
|
|
see the two especially dedicated to web stuff in the question on |
2421 |
|
|
books. For problems and questions related to the web, like "Why |
2422 |
|
|
do I get 500 Errors" or "Why doesn't it run from the browser right |
2423 |
|
|
when it runs fine on the command line", see the troubleshooting |
2424 |
|
|
guides and references in L<perlfaq9> or in the CGI MetaFAQ: |
2425 |
|
|
|
2426 |
|
|
=end original |
2427 |
|
|
|
2428 |
|
|
モジュールなら、CPAN から CGI モジュールや LWP モジュールを入手しましょう。 |
2429 |
|
|
教科書なら、本にある web stuff の特に決定的な二つを参照しましょう。 |
2430 |
|
|
“Why do I get 500 Errors” (なんで 500 Errors になるの) |
2431 |
|
|
“Why doesn't it run from the browser right when it runs fine on the command line” |
2432 |
|
|
(なぜコマンドラインからだとちゃんと動くのに、ブラウザーからだと |
2433 |
|
|
だめなんでしょうか)のように web に関連する問題や疑問は |
2434 |
|
|
L<perlfaq9> か CGI MetaFAQ を参照してください: |
2435 |
|
|
|
2436 |
|
|
http://www.perl.org/CGI_MetaFAQ.html |
2437 |
|
|
|
2438 |
|
|
=head2 Where can I learn about object-oriented Perl programming? |
2439 |
|
|
|
2440 |
|
|
(オブジェクト指向の Perl プログラミングはどこで学べますか?) |
2441 |
|
|
|
2442 |
|
|
=begin original |
2443 |
|
|
|
2444 |
|
|
A good place to start is L<perltoot>, and you can use L<perlobj>, |
2445 |
|
|
L<perlboot>, L<perltoot>, L<perltooc>, and L<perlbot> for reference. |
2446 |
|
|
|
2447 |
|
|
=end original |
2448 |
|
|
|
2449 |
|
|
始めるにはよい場所は L<perltoot>です。 |
2450 |
|
|
リファレンスとしてL<perlobj>, L<perlboot>, <perltooc>, |
2451 |
|
|
<perlbot> が使えます。 |
2452 |
|
|
|
2453 |
|
|
=begin original |
2454 |
|
|
|
2455 |
|
|
A good book on OO on Perl is the "Object-Oriented Perl" |
2456 |
|
|
by Damian Conway from Manning Publications, or "Intermediate Perl" |
2457 |
|
|
by Randal Schwartz, brian d foy, and Tom Phoenix from O'Reilly Media. |
2458 |
|
|
|
2459 |
|
|
=end original |
2460 |
|
|
|
2461 |
|
|
Perl でのオブジェクト指向に関するよい本は Manning Publications が |
2462 |
|
|
出版する Damian Conway による "Object-Oriented Perl" か、 |
2463 |
|
|
O'Reilly Media が出版する Randal Schwartz, brian d foy, |
2464 |
|
|
Tom Phoenix による "Intermediate Perl" です。 |
2465 |
|
|
|
2466 |
|
|
=head2 Where can I learn about linking C with Perl? |
2467 |
|
|
|
2468 |
|
|
(C と Perl のリンクについてはどこで学べますか?) |
2469 |
|
|
|
2470 |
|
|
=begin original |
2471 |
|
|
|
2472 |
|
|
If you want to call C from Perl, start with L<perlxstut>, |
2473 |
|
|
moving on to L<perlxs>, L<xsubpp>, and L<perlguts>. If you want to |
2474 |
|
|
call Perl from C, then read L<perlembed>, L<perlcall>, and |
2475 |
|
|
L<perlguts>. Don't forget that you can learn a lot from looking at |
2476 |
|
|
how the authors of existing extension modules wrote their code and |
2477 |
|
|
solved their problems. |
2478 |
|
|
|
2479 |
|
|
=end original |
2480 |
|
|
|
2481 |
|
|
もし Perl から C を呼び出したいのなら、L<perlxstut> から始めて L<perlxs>, |
2482 |
|
|
L<xsubpp>, L<perlguts> へと進みます。 |
2483 |
|
|
C から Perl を呼び出したいのなら、L<perlembed>, L<perlcall>, L<perlguts> を |
2484 |
|
|
読みましょう。 |
2485 |
|
|
すでにあるエクステンションの作者がどのようにそれを記述し、 |
2486 |
|
|
どのように彼らの問題を解決したのかを見ることで多くのことが |
2487 |
|
|
学べるのだということを忘れないでください。 |
2488 |
|
|
|
2489 |
|
|
=begin original |
2490 |
|
|
|
2491 |
|
|
You might not need all the power of XS. The Inline::C module lets |
2492 |
|
|
you put C code directly in your Perl source. It handles all the |
2493 |
|
|
magic to make it work. You still have to learn at least some of |
2494 |
|
|
the perl API but you won't have to deal with the complexity of the |
2495 |
|
|
XS support files. |
2496 |
|
|
|
2497 |
|
|
=end original |
2498 |
|
|
|
2499 |
|
|
XS の力の全てが必要なわけではないかもしれません。 |
2500 |
|
|
The Inline::C モジュールは Perl のソースの中に C のコードを直接書くことが |
2501 |
|
|
できます。 |
2502 |
|
|
これはこれが動作するための全ての魔法を扱います。 |
2503 |
|
|
それでも少なくとも perl API の一部は学習する必要がありますが、XS サポート |
2504 |
|
|
ファイルの複雑を扱う必要はありません。 |
2505 |
|
|
|
2506 |
|
|
=head2 I've read perlembed, perlguts, etc., but I can't embed perl in my C program; what am I doing wrong? |
2507 |
|
|
|
2508 |
|
|
(perlembed や perlguts なんかを読んだのだけど、私の C プログラムに perl を組み込めません。何が悪いのでしょうか?) |
2509 |
|
|
|
2510 |
|
|
=begin original |
2511 |
|
|
|
2512 |
|
|
Download the ExtUtils::Embed kit from CPAN and run `make test'. If |
2513 |
|
|
the tests pass, read the pods again and again and again. If they |
2514 |
|
|
fail, see L<perlbug> and send a bug report with the output of |
2515 |
|
|
C<make test TEST_VERBOSE=1> along with C<perl -V>. |
2516 |
|
|
|
2517 |
|
|
=end original |
2518 |
|
|
|
2519 |
|
|
CPAN から ExtUtils::Embed キットをダウンロードして、`make test'を |
2520 |
|
|
実行してください。 |
2521 |
|
|
もしこのテストに合格したのなら、pod を何度も何度もくり返しくり返し |
2522 |
|
|
読んでください。 |
2523 |
|
|
テストに失敗したなら、L<perlbug> を読んで、C<perl -V> の出力と |
2524 |
|
|
C<make test TEST_VERBOSE=1> の出力を添付してバグレポートを送ってください。 |
2525 |
|
|
|
2526 |
|
|
=head2 When I tried to run my script, I got this message. What does it mean? |
2527 |
|
|
|
2528 |
|
|
(私のスクリプトを実行したとき、こんなメッセージを受け取りました。これって何を意味しているのでしょうか?) |
2529 |
|
|
|
2530 |
|
|
=begin original |
2531 |
|
|
|
2532 |
|
|
A complete list of Perl's error messages and warnings with explanatory |
2533 |
|
|
text can be found in L<perldiag>. You can also use the splain program |
2534 |
|
|
(distributed with Perl) to explain the error messages: |
2535 |
|
|
|
2536 |
|
|
=end original |
2537 |
|
|
|
2538 |
|
|
perl のすべてのエラーメッセージ、警告メッセージの説明テキスト付きのリストが |
2539 |
|
|
L<perldiag> にあります。 |
2540 |
|
|
エラーメッセージを説明するために、splain プログラムを |
2541 |
|
|
使うこともできます(これは Perl と一緒に配布されています)。 |
2542 |
|
|
|
2543 |
|
|
perl program 2>diag.out |
2544 |
|
|
splain [-v] [-p] diag.out |
2545 |
|
|
|
2546 |
|
|
=begin original |
2547 |
|
|
|
2548 |
|
|
or change your program to explain the messages for you: |
2549 |
|
|
|
2550 |
|
|
=end original |
2551 |
|
|
|
2552 |
|
|
あるいは、以下のようにしてメッセージを説明的にするようにプログラムを |
2553 |
|
|
変更します: |
2554 |
|
|
|
2555 |
|
|
use diagnostics; |
2556 |
|
|
|
2557 |
|
|
=begin original |
2558 |
|
|
|
2559 |
|
|
or |
2560 |
|
|
|
2561 |
|
|
=end original |
2562 |
|
|
|
2563 |
|
|
または |
2564 |
|
|
|
2565 |
|
|
use diagnostics -verbose; |
2566 |
|
|
|
2567 |
|
|
=head2 What's MakeMaker? |
2568 |
|
|
|
2569 |
|
|
(MakeMaker ってなんですか?) |
2570 |
|
|
|
2571 |
|
|
=begin original |
2572 |
|
|
|
2573 |
|
|
(contributed by brian d foy) |
2574 |
|
|
|
2575 |
|
|
=end original |
2576 |
|
|
|
2577 |
|
|
(brian d foy によって寄贈されました) |
2578 |
|
|
|
2579 |
|
|
=begin original |
2580 |
|
|
|
2581 |
|
|
The C<ExtUtils::MakeMaker> module, better known simply as "MakeMaker", |
2582 |
|
|
turns a Perl script, typically called C<Makefile.PL>, into a Makefile. |
2583 |
|
|
The Unix tool C<make> uses this file to manage dependencies and actions |
2584 |
|
|
to process and install a Perl distribution. |
2585 |
|
|
|
2586 |
|
|
=end original |
2587 |
|
|
|
2588 |
|
|
単に "MakeMaker" としてよく知られている C<ExtUtils::MakeMaker> モジュールは、 |
2589 |
|
|
(典型的には C<Makefile.PL> という名前の) Perl スクリプトを Makefile に |
2590 |
|
|
変換します。 |
2591 |
|
|
Unix ツール C<make> は Perl 配布を処理してインストールするための依存と |
2592 |
|
|
作業を管理します。 |
2593 |
|
|
|
2594 |
|
|
=head1 AUTHOR AND COPYRIGHT |
2595 |
|
|
|
2596 |
|
|
Copyright (c) 1997-2010 Tom Christiansen, Nathan Torkington, and |
2597 |
|
|
other authors as noted. All rights reserved. |
2598 |
|
|
|
2599 |
|
|
This documentation is free; you can redistribute it and/or modify it |
2600 |
|
|
under the same terms as Perl itself. |
2601 |
|
|
|
2602 |
|
|
Irrespective of its distribution, all code examples here are in the public |
2603 |
|
|
domain. You are permitted and encouraged to use this code and any |
2604 |
|
|
derivatives thereof in your own programs for fun or for profit as you |
2605 |
|
|
see fit. A simple comment in the code giving credit to the FAQ would |
2606 |
|
|
be courteous but is not required. |
2607 |
|
|
|
2608 |
|
|
=begin meta |
2609 |
|
|
|
2610 |
|
|
Translate: 吉村 寿人 <JAE00534@niftyserve.or.jp> |
2611 |
|
|
Update: SHIRAKATA Kentaro <argrath@ub32.org> (5.6.1-) |
2612 |
|
|
Status: completed |
2613 |
|
|
|
2614 |
|
|
=end meta |
2615 |
|
|
|