.\" Copyright (c) 2000 Josef Karthauser <joe@FreeBSD.org> .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL [your name] OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" %FreeBSD: src/share/man/man7/style.perl.7,v 1.12.2.2 2001/03/06 19:08:20 ru Exp % .\" $FreeBSD: doc/ja_JP.eucJP/man/man7/style.perl.7,v 1.5 2001/05/14 01:09:43 horikawa Exp $ .\" .Dd October 16, 2000 .Dt STYLE.PERL 7 .Os FreeBSD .Sh ̾�� .Nm style.perl .Nd "FreeBSD Perl �������ե�����Υ������륬����" .Sh ���� ���Υե������ .Fx �������ĥ�� perl ������ץȤ˹��ޤ�������������������Ƥ��ޤ��� .Bd -literal # # Perl �Τ���Υ������륬���ɤǤ��������ͥ�Υ������륬���ɤ˴�Ť��Ƥ��ޤ��� # # # �ȤƤ���פ� 1 �ԤΥ����ȤϤ��Τ褦�ˤ��ޤ��� # # �ۤȤ�ɤ� 1 �ԥ����ȤϤ��Τ褦�ˤ��ޤ��� # ʣ���Ԥˤ錄�륳���ȤϤ��Τ褦�ˤ��ޤ����ºݤ�ʸ�Ϥ�ޤ����ºݤ� # ����˸�����褦�����Ƥ����ޤ��� .Ed .Pp ���ƤΥ�����ץȤˤϥ�����ץȤ���Ƭ������֥��å��ȡ� ���Υ�����ץȤ������ΤʤΤ��Ҥ��������ȥ֥��å����֤��٤� �Ǥ��� .Bd -literal #!/usr/bin/perl -w # ��� # �֥��å� # ���Υ�����ץȤ�ɸ�����Ϥ���Ť������ͥ�����ե�������ɤ߹��ߡ� # ɸ����Ϥ˿����������Υҥ�ȥե��������Ϥ��ޤ��� .Ed .Pp ���ƤΥ�����ץȤ� .Xr strict 3 �⥸�塼�����Ѥ��Ʒٹ�ʤ���ư��ʤ���Ф����ޤ����㤨�С� ���Τ褦�ˤ��ޤ�: .Bd -literal #!/usr/bin/perl -w # �����������ץȤ����Ƶ��ҡ�����¾ use strict; \&... .Ed .Pp ��ǽ�ʾ��Ǥϥ�����ץȤ� taint (����) �⡼�ɤˤ��� ư����Ƥ������������Τ��Ȥ� .Xr perlsec 1 ��ʸ����Ƥ��ޤ��� .Bd -literal #!/usr/bin/perl -wT .Ed .Pp �ᥤ��ץ������� MAIN: �ȥ�٥뤵�줿�֥��å����֤��٤��Ǥ��� ����ˤ���礭�� perl ������ץȤdz��������̤���Τ��ưפˤʤꡢ �ޤ��ᥤ��ץ����������ǻ��Ѥ�����ѿ����Ф��ƥ������פ�Ϳ���ޤ��� .Bd -literal MAIN:{ print(foo("/usr/bin/man", "7", "style.perl")); exit(0); } .Ed .Pp ���ƤΥ��֥롼����� .Xr perlsub 1 ���������Ƥ���褦�ʥץ��ȥ����װ�������Ѥ����������٤��Ǥ��� .Bd -literal sub foo($@) { my $cmd = shift; my @args = @_; } .Ed .Pp ���Ƥ��ѿ��ϻ��Ѥ��������������٤��Ǥ�������� .Ic use strict �������Ѥ�����϶�������ޤ��� .Pp ���������ѿ��Υ������פ�����ˤ� .Ic local .Va $variable �ǤϤʤ� .Ic my .Va $variable ���Ѥ���٤��Ǥ��� .Ic local ����Ϥ��줬ɬ�פȤ������̤ˤΤ��Ѥ����ǥե���ȤǤϻ��Ѥ��٤��Ǥ� ����ޤ��� ��������� perl4 ������ץȤǤϡ� .Ic my ����� perl5 �����ˤ�¸�ߤ��ʤ��ä��Ȥ�����ͳ�� .Ic local ����Ѥ��Ƥ��ޤ��� .Pp ¿���ξ�硢�������Х��ѿ��ϥ����ɤ���Ƭ�� .Xr vars 3 ����֥��å�����Ѥ����������٤��Ǥ�: .Bd -literal use vars qw($globalscalar @globalarray %globalhash); .Ed .Pp ���ˤ�äƤϥ�����ץȤ���Ƭ�� .Xr vars 3 ����ǤϤʤ� .Ic my ʸ���Ѥ���Τ�Ŭ���Ƥ��뤳�Ȥ⤢��ޤ��� .Pp ���Ƥ��ѿ��ˤϥ����Ȥ�Ĥ���٤��Ǥ��� .Bd -literal sub foo($@) { my $cmd = shift; # �¹Ԥ��륳�ޥ�� my @args = @_; # $cmd �ؤΰ��� } .Ed .Pp ���������ѿ��϶��Ԥˤ�äƴؿ��ΰ�����ʬΥ����٤��Ǥ�: .Bd -literal sub foo($@) { my $cmd = shift; # �¹Ԥ��륳�ޥ�� my @args = @_; # command �ؤΰ��� my $pid; # �Ҥ� PID local *PIPE; # �ѥ��� my $output; # ���ޥ�ɤ���ν��� } .Ed .Pp ��ǽ�ʻ��ˤϤ��ĤǤ⡢ �����ɤϥ����ɥ����å� .Nm perl .Fl wc .Ar script.pl �ޤ��� .Nm perl .Fl wcT .Ar script.pl ���̲ᤵ���Ƥ������������ΤȤ����ٹ���������ƤϤ����ޤ��� .Pp ����ǥ�Ȥ� 8 ʸ���Υ��֤Ǥ��� �� 2 ��٥�Υ���ǥ�Ȥ� 4 ʸ���Υ��ڡ����Ǥ��� .Bd -literal while (cnt < 20) { z = a + really + long + statement + that + needs + two lines + gets + indented + four + spaces + on + the + second + and + subsequent + lines. } .Ed .Pp ����ʸ����������ɲä��ƤϤ����ޤ��� �ޤ�������ǥ�Ȥ�������뤿��ˡ����ڡ��������ˤϥ��֤Τߤ���Ѥ��� ���������� ���֤����߽Ф��ʾ�Υ��ڡ�������ӥ��֤����˥��ڡ�������Ѥ��Ƥ� �����ޤ��� .Pp �֥졼���γ��Ϥ�����ԤκǸ���֤���ޤ��� else �� elsif ��ľ���� if �ޤ��� elsif �֥��å��ν�λ�֥졼���� Ʊ���Ԥ��֤���ޤ�: .Bd -literal sub foo($@) { my $cmd = shift; # �¹Ԥ��륳�ޥ�� my @args = @_; # ���ޥ�ɤؤΰ��� my $pid; # �Ҥ� PID local *PIPE; # �ѥ��� my $output; # ���ޥ�ɤ���ν��� unless (defined($pid = open(PIPE, "-|"))) { die("open(): $!\\n"); } elsif ($pid == 0) { exec($cmd, @args); die("exec(): $!\\n"); } $output = ""; while (<PIPE>) { $output .= $_; } waitpid($pid, 0); if ($? & 0xff) { die("$cmd caught a signal " . ($? & 0x7f) . "\\n"); } elsif ($?) { die("$cmd returned exit code " . ($? >> 8) . "\\n"); } return $output; } .Ed .Pp ��ǽ�ʾ��Ǥϡ�������ץȤ�ɸ��⥸�塼�����Ѥ��� �����ɤξ�˽�ľ���ƤϤ����ޤ��� ���Τ��Ȥ�¥�ʤ��뤿��ˡ� CPAN �⥸�塼�����ܥ����ƥ�� �����ळ�Ȥ�Ŭ���Ƥ����礬���뤫�⤷��ޤ��� .Pp Ŭ�ڤʽ�Ǥϡ� .Ic chop �ǤϤʤ� .Ic chomp ����Ѥ��Ƥ��������� .Pp ���������������ˤ� .Ic if Pq Cm \&! No ...\& �ǤϤʤ� .Ic unless ����Ѥ��Ƥ��������� .Pp ���Υ����ɤ�̷�⤷�ʤ��ϰϤ� .Xr perlstyle 1 ���ɤ�� Larry Wall �ο侩�����������Ѥ��Ƥ��������� .Sh ��Ϣ���� .Xr perlsec 1 , .Xr perlstyle 1 , .Xr style 9 .Sh ��� ���Υޥ˥奢��ڡ����ϡ� .Fx �� .Xr style 9 �ޥ˥奢��ڡ������礭����Ť��Ƥ��ޤ���