=encoding euc-jp =head1 NAME X X =begin original perlsub - Perl subroutines =end original perlsub - Perl �Υ��֥롼���� =head1 SYNOPSIS =begin original To declare subroutines: X X =end original ���֥롼������������ˤ�: X X =begin original sub NAME; # A "forward" declaration. sub NAME(PROTO); # ditto, but with prototypes sub NAME : ATTRS; # with attributes sub NAME(PROTO) : ATTRS; # with attributes and prototypes =end original sub NAME; # "���" ��� sub NAME(PROTO); # Ʊ�塣�������ץ��ȥ������դ� sub NAME : ATTRS; # °���դ� sub NAME(PROTO) : ATTRS; # °���ȥץ��ȥ������դ� =begin original sub NAME BLOCK # A declaration and a definition. sub NAME(PROTO) BLOCK # ditto, but with prototypes sub NAME : ATTRS BLOCK # with attributes sub NAME(PROTO) : ATTRS BLOCK # with prototypes and attributes =end original sub NAME BLOCK # �������� sub NAME(PROTO) BLOCK # Ʊ�塣�������ץ��ȥ������դ� sub NAME : ATTRS BLOCK # °���դ� sub NAME(PROTO) : ATTRS BLOCK # �ץ��ȥ����פ�°���դ� =begin original To define an anonymous subroutine at runtime: X =end original �¹Ի���̵̾���֥롼������������ˤ�: X =begin original $subref = sub BLOCK; # no proto $subref = sub (PROTO) BLOCK; # with proto $subref = sub : ATTRS BLOCK; # with attributes $subref = sub (PROTO) : ATTRS BLOCK; # with proto and attributes =end original $subref = sub BLOCK; # �ץ��ȥ����פʤ� $subref = sub (PROTO) BLOCK; # �ץ��ȥ������դ� $subref = sub : ATTRS BLOCK; # °���դ� $subref = sub (PROTO) : ATTRS BLOCK; # �ץ��ȥ����פ�°���դ� =begin original To import subroutines: X =end original ���֥롼����򥤥�ݡ��Ȥ���ˤ�: X use MODULE qw(NAME1 NAME2 NAME3); =begin original To call subroutines: X X =end original ���֥롼�����ƤӽФ��ˤ�: X X =begin original NAME(LIST); # & is optional with parentheses. NAME LIST; # Parentheses optional if predeclared/imported. &NAME(LIST); # Circumvent prototypes. &NAME; # Makes current @_ visible to called subroutine. =end original NAME(LIST); # ���ä����դ��Ƥ���Ȥ��� & �Ͼ�ά��ǽ�� NAME LIST; # ͽ�����/����ݡ��Ȥ���Ƥ���ʤ餫�ä��Ͼ�ά��ǽ�� &NAME(LIST); # �ץ��ȥ����פ���򤹤롣 &NAME; # �ƤӽФ��줿���֥롼���󤫤鸽�ߤ� @_ ��Ļ벽���롣 =head1 DESCRIPTION =begin original Like many languages, Perl provides for user-defined subroutines. These may be located anywhere in the main program, loaded in from other files via the C, C, or C keywords, or generated on the fly using C or anonymous subroutines. You can even call a function indirectly using a variable containing its name or a CODE reference. =end original ¿���θ����Ʊ�͡�Perl �ϥ桼��������Υ��֥롼������󶡤��Ƥ��ޤ��� �����Υ��֥롼����ϡ��ᥤ��ץ������Τɤ��ˤǤ��֤����Ȥ��Ǥ��� C, C, C �Ȥ��ä�������ɤ�Ȥä�¾�Υե����뤫�� �����ɤ��뤳�Ȥ��Ǥ���C ��̵̾���֥롼�����Ȥä� �������뤳�Ȥ�Ǥ��ޤ��� ���֥롼�����̾���䡢�����ɥ�ե���󥹤��ݻ������ѿ���Ȥä� ����Ū�˴ؿ���ƤӽФ����Ȥ��ǽ�Ǥ��� =begin original The Perl model for function call and return values is simple: all functions are passed as parameters one single flat list of scalars, and all functions likewise return to their caller one single flat list of scalars. Any arrays or hashes in these call and return lists will collapse, losing their identities--but you may always use pass-by-reference instead to avoid this. Both call and return lists may contain as many or as few scalar elements as you'd like. (Often a function without an explicit return statement is called a subroutine, but there's really no difference from Perl's perspective.) X X =end original Perl �Ǥδؿ��ƤӽФ�������ͤΥ�ǥ��ñ��Ǥ������Ƥδؿ��ϰ����� ʿó�ǰ�ĤΥ�����Υꥹ�ȤǼ�����ꡢƱ�ͤ����Ƥδؿ��ϸƤӽФ����� �Ф���ʿó�ǰ�ĤΥ�����Τꥹ�Ȥ��֤��Ȥ�����ΤǤ��� �����θƤӽФ��ꥹ�Ȥ�����ͥꥹ�Ȥˤ������Ƥ�����ȥϥå���ϡ� �٤���Ƥ��Υ����ǥ�ƥ��ƥ��򼺤��ޤ��� ��������������򤱤뤿��˾�˥�ե���󥹤��Ϥ����Ȥ��Ǥ��ޤ��� �ƤӽФ��ꥹ�Ȥ�����ͥꥹ�Ȥ�ξ���Ȥ⹥���ʤ����ο��Υ������ �ݻ����뤳�Ȥ��Ǥ��ޤ�(���Τ� return ʸ�Τʤ��ؿ��Ϥ��Ф��Х��֥롼����� �ƤФ�ޤ�����Perl �������Ϥ����δ֤˲��ΰ㤤�⤢��ޤ���)�� =begin original Any arguments passed in show up in the array C<@_>. Therefore, if you called a function with two arguments, those would be stored in C<$_[0]> and C<$_[1]>. The array C<@_> is a local array, but its elements are aliases for the actual scalar parameters. In particular, if an element C<$_[0]> is updated, the corresponding argument is updated (or an error occurs if it is not updatable). If an argument is an array or hash element which did not exist when the function was called, that element is created only when (and if) it is modified or a reference to it is taken. (Some earlier versions of Perl created the element whether or not the element was assigned to.) Assigning to the whole array C<@_> removes that aliasing, and does not update any arguments. X X X<@_> =end original �롼������Ϥ���뤹�٤Ƥΰ��������� C<@_> ���֤���ޤ��� �������äơ�����ؿ�����Ĥΰ������դ��ƸƤӽФ����ʤ�С� ���ΰ����� C<$_[0]> �� C<$_[1]> �˳�Ǽ����ޤ��� ���� C<@_> �� local ����Ǥ������������Ǥϼºݤ� ������ѥ�᡼������̾�Ǥ��� ���Ȥ��� C<$_[0]> ���������줿��硢�б������������������ޤ� (�����Ǥ��ʤ����ˤϥ��顼�Ȥʤ�ޤ�)�� �������������ϥå����(�ؿ����ƤӽФ��줿�����Ǥ�¸�ߤ��Ƥʤ�) ���ǤǤ��ä���硢�������Ǥ�(�б�������̾��)�������줿�� ��ե���󥹤����줿�Ȥ��ˤΤߺ�������ޤ��� (�����ΰ����ΥС������� Perl �Ǥϡ��������Ǥ��������Ԥ��褦���Ԥ��ޤ��� ��������Ƥ��ޤ�����) ���� C<@_> ���Τ��Ф�����������̾���˴��������ΰ����⹹�����ޤ��� X X X<@_> =begin original A C statement may be used to exit a subroutine, optionally specifying the returned value, which will be evaluated in the appropriate context (list, scalar, or void) depending on the context of the subroutine call. If you specify no return value, the subroutine returns an empty list in list context, the undefined value in scalar context, or nothing in void context. If you return one or more aggregates (arrays and hashes), these will be flattened together into one large indistinguishable list. =end original ���֥롼���󤫤�æ�Ф��뤿��˻Ȥ�줿 C ʸ�� �Ȥ��뤳�Ȥ⤢��ޤ��������֥롼����ƤӽФ��Υ���ƥ����Ȥˤ�ä� Ŭ�ڤʥ���ƥ�����(�ꥹ�ȡ������顢̵��)��ɾ�����������ͤλ���� ��ά���������ǽ�Ǥ��� �⤷��������ͤ���ꤷ�ʤ���С����֥롼����ϥꥹ�ȥ���ƥ����Ȥˤ����Ƥ� ���ꥹ�Ȥ��֤��������饳��ƥ����Ȥˤ����Ƥ�̤����ͤ��֤��� ̵������ƥ����ȤǤϤʤˤ��֤��ޤ��� ��Ĥޤ���ʣ���ν����� (�����ϥå���) ���֤���硢��Ĥ��礭�ʶ��̤Ǥ��ʤ� �ꥹ�Ȥ�ʿ�IJ�����ޤ��� =begin original If no C is found and if the last statement is an expression, its value is returned. If the last statement is a loop control structure like a C or a C, the returned value is unspecified. The empty sub returns the empty list. X X X =end original C ���ʤ����Ǹ��ʸ�������ä���硢�����ͤ��֤���ޤ��� �Ǹ��ʸ�� C �� C �Τ褦�ʥ롼�����湽¤���ä���硢 �֤�����ͤ�����Ǥ��� ���Υ��֥롼����϶��ꥹ�Ȥ��֤��ޤ��� X X X =begin original Perl does not have named formal parameters. In practice all you do is assign to a C list of these. Variables that aren't declared to be private are global variables. For gory details on creating private variables, see L<"Private Variables via my()"> and L<"Temporary Values via local()">. To create protected environments for a set of functions in a separate package (and probably a separate file), see L. X X =end original Perl��̾���դ�����������äƤ��ޤ��� C �ˤ����Υꥹ�Ȥ��������뤳�ȤǹԤ��ޤ��� �ץ饤�١��ȤǤ����������줺�˻Ȥ��Ƥ����ѿ������ƥ������Х��ѿ��Ǥ��� �ץ饤�١����ѿ��˴ؤ���ܺ٤�L<"Private Variables via my()"> �� L<"Temporary Values via local()"> �򻲾Ȥ��Ƥ��������� �ѥå�������(�����餯�ϥե�����Ǥ�)ʬ�����Ƥ���ؿ��Υ��åȤΤ���� �ݸ�줿�Ķ�����ˤ� L �򻲾Ȥ��Ƥ��������� X X =begin original Example: =end original ��: sub max { my $max = shift(@_); foreach $foo (@_) { $max = $foo if $max < $foo; } return $max; } $bestday = max($mon,$tue,$wed,$thu,$fri); =begin original Example: =end original ��: =begin original # get a line, combining continuation lines # that start with whitespace =end original # �Ԥ��ꡢ����ǻϤޤ��³�Ԥ�Ϣ�뤷�ޤ� sub get_line { $thisline = $lookahead; # global variables! LINE: while (defined($lookahead = )) { if ($lookahead =~ /^[ \t]/) { $thisline .= $lookahead; } else { last LINE; } } return $thisline; } $lookahead = ; # get first line while (defined($line = get_line())) { ... } =begin original Assigning to a list of private variables to name your arguments: =end original ������̾�����դ��뤿��˥ץ饤�١����ѿ��Υꥹ�Ȥ���������: sub maybeset { my($key, $value) = @_; $Foo{$key} = $value unless $Foo{$key}; } =begin original Because the assignment copies the values, this also has the effect of turning call-by-reference into call-by-value. Otherwise a function is free to do in-place modifications of C<@_> and change its caller's values. X X =end original ����ϡ������Ϥ������Ϥ��ˤ�����̤⤢��ޤ�; �ʤ��ʤ顢�ͤΥ��ԡ��� �������Ƥ��뤫��Ǥ��� ���Τ褦�ˤ��ʤ��ΤǤ���С��ؿ��ϼ�ͳ�� C<@_> ���ͤ򤽤ξ�� �񤭴����뤳�Ȥ��Ǥ�������Ϥ��Τޤ޸ƤӽФ�¦���ͤ��ѹ����ޤ��� X X upcase_in($v1, $v2); # this changes $v1 and $v2 sub upcase_in { for (@_) { tr/a-z/A-Z/ } } =begin original You aren't allowed to modify constants in this way, of course. If an argument were actually literal and you tried to change it, you'd take a (presumably fatal) exception. For example, this won't work: X X =end original ������󡢤��Τ������������ѹ����뤳�Ȥϵ�����ޤ��� ����������ºݤˤϥ�ƥ��Ǥ��ä����ˤ��ΰ������ѹ����褦�Ȥ���ȡ� (�����餯����̿Ū��)�㳰��������������뤳�Ȥˤʤ�Ǥ��礦�� �㤨�м�����Ϥ��ޤ�Ư���ޤ���: X X upcase_in("frederick"); =begin original It would be much safer if the C function were written to return a copy of its parameters instead of changing them in place: =end original C �ؿ�������ʤ�Τˤ���ˤϡ��ѥ�᡼�����Τ�Τ� �񤭴�����ΤǤϤʤ����Υ��ԡ����֤��褦�˵��Ҥ���褦�ˤ��ޤ�: ($v3, $v4) = upcase($v1, $v2); # this doesn't change $v1 and $v2 sub upcase { return unless defined wantarray; # void context, do nothing my @parms = @_; for (@parms) { tr/a-z/A-Z/ } return wantarray ? @parms : $parms[0]; } =begin original Notice how this (unprototyped) function doesn't care whether it was passed real scalars or arrays. Perl sees all arguments as one big, long, flat parameter list in C<@_>. This is one area where Perl's simple argument-passing style shines. The C function would work perfectly well without changing the C definition even if we fed it things like this: =end original ����(�ץ��ȥ����פ��Ĥ��Ƥ��ʤ�)�ؿ�����ʬ���Ф��������Υ����餬 �Ϥ��줿�Τ������Ϥ��줿�Τ��򵤤ˤ��Ƥ��ʤ��Ȥ������Ȥ����դ��Ƥ��������� Perl �ϰ�Ĥε����ʿó��(�ꥹ�Ȥ���˥ꥹ�Ȥ��ޤޤ�뤳�ȤϤʤ��� �Ȥ�������) C<@_> �ѥ�᡼���ꥹ�ȤȤ������Ƥΰ����򸫤�ΤǤ��� ����� Perl ��ñ��ʰ����Ϥ��η����Τ�����ΰ�ĤǤ��� ���� C �ؿ��ϡ��ʲ��Τ褦�ʸƤӽФ��򤷤����Ǥ� C �� ������ѹ����뤳�Ȥʤ�������ư��ޤ�: @newlist = upcase(@list1, @list2); @newlist = upcase( split /:/, $var ); =begin original Do not, however, be tempted to do this: =end original ���������ʲ��Τ褦�ʸƤӽФ��������Ȥ��ƤϤ����ޤ���: (@a, @b) = upcase(@list1, @list2); =begin original Like the flattened incoming parameter list, the return list is also flattened on return. So all you have managed to do here is stored everything in C<@a> and made C<@b> empty. See L for alternatives. =end original �ؿ����Ϥ��������ꥹ�Ȥ�ʿó�ʥꥹ�ȤǤ���Τ�Ʊ�͡�����ͤΥꥹ�Ȥ� �ޤ�ʿó�ʥꥹ�ȤǤ��� �Ǥ����顢�ؿ����֤������Ƥ����Ǥ� C<@a> �˳�Ǽ���졢C<@b> �� ���ˤʤ�ޤ��� �̤Τ�����ˤĤ��Ƥ� L �򻲾Ȥ��Ƥ��������� =begin original A subroutine may be called using an explicit C<&> prefix. The C<&> is optional in modern Perl, as are parentheses if the subroutine has been predeclared. The C<&> is I optional when just naming the subroutine, such as when it's used as an argument to defined() or undef(). Nor is it optional when you want to do an indirect subroutine call with a subroutine name or reference using the C<&$subref()> or C<&{$subref}()> constructs, although the C<< $subref->() >> notation solves that problem. See L for more about all that. X<&> =end original ���֥롼����ϡ�����Ū�� C<&> �Ȥ����ץ�ե��å������դ��ƸƤӽФ����Ȥ� �Ǥ��ޤ��� �Ƕ�� Perl �Ǥ� C<&> �Ͼ�ά��ǽ�Ǥ��ꡢ���֥롼���󤬤��餫���� �������Ƥ�����ˤϳ�̤��ά�Ǥ��ޤ��� defined() �� undef() �ΰ����Ȥ��ƻȤä��褦�ʡ�ñ�ʤ�̾���դ� ���֥롼����Ǥ���Ȥ��� C<&> �� B<��ά��ǽ�ǤϤ���ޤ���>�� C<&$subref()> �� C<&{$subref}()> �Τ褦�ʡ����֥롼�����̾���� ��ե���󥹤�Ȥä�����Ū�ʥ��֥롼��ƤӽФ���Ԥ����������Ȥ��ˤ� C<&> �Ͼ�ά���뤳�ȤϤǤ��ޤ���; â�� C<< $subref->() >> �ε�ˡ������� ��褷�ޤ��� �ܤ����� L �򻲾Ȥ��Ƥ��������� X<&> =begin original Subroutines may be called recursively. If a subroutine is called using the C<&> form, the argument list is optional, and if omitted, no C<@_> array is set up for the subroutine: the C<@_> array at the time of the call is visible to subroutine instead. This is an efficiency mechanism that new users may wish to avoid. X =end original ���֥롼����ϺƵ�Ū�˸ƤӽФ����Ȥ�Ǥ��ޤ��� ���륵�֥롼���� C<&> �դ��ǸƤӽФ��줿�ʤ顢�����ꥹ�ȤϾ�ά��ǽ�ǡ� �⤷��ά���줿�ʤ顢���Υ��֥롼������Ф��� C<@_> ��������ꤵ��ޤ���: ����˸ƤӽФ����� C<@_> ���󤬥��֥롼������Ф��ƲĻ�Ȥʤ�ޤ��� ����Ͽ������桼�������򤱤����Ȼפ�����Ū�ʥᥫ�˥���Ǥ��� X =begin original &foo(1,2,3); # pass three arguments foo(1,2,3); # the same =end original &foo(1,2,3); # ���Ĥΰ������Ϥ� foo(1,2,3); # ���Ʊ�� =begin original foo(); # pass a null list &foo(); # the same =end original foo(); # ���ꥹ�Ȥ��Ϥ� &foo(); # ���Ʊ�� =begin original &foo; # foo() get current args, like foo(@_) !! foo; # like foo() IFF sub foo predeclared, else "foo" =end original &foo; # foo() �� foo(@_) ��Ʊ�͸��ߤΰ�������!! foo; # ���֥롼���� foo ��ͽ���������Ƥ�����˸¤� # foo() ��Ʊ�͡�����ʳ��Ǥ� "foo" =begin original Not only does the C<&> form make the argument list optional, it also disables any prototype checking on arguments you do provide. This is partly for historical reasons, and partly for having a convenient way to cheat if you know what you're doing. See L below. X<&> =end original C<&> �����ϰ����ꥹ�Ȥ��ά��ǽ�ˤ���Ф���Ǥʤ���Ϳ����줿������ �Ф��뤹�٤ƤΥץ��ȥ����ץ����å���̵���ˤ��ޤ��� ����ϰ����ˤ����Ū����ͳ�Ǥ��ꡢ�����ˤϤ��ʤ�����ʬ�ιԤäƤ���ư��� �狼�äƤ���Ȥ��ˤ��ޤ����ޤ�����Ԥ���������ˡ��Ĥ��Ƥ�������Ǥ��� ��˽ФƤ��� L �򻲾Ȥ��Ƥ��������� X<&> =begin original Since Perl 5.16.0, the C<__SUB__> token is available under C and C. It will evaluate to a reference to the currently-running sub, which allows for recursive calls without knowing your subroutine's name. =end original Perl 5.16.0 ���顢C �ޤ��� C ��ͭ���� ���� C<__SUB__> �ȡ��������Ѳ�ǽ�Ǥ��� ����ϸ��߼¹Ԥ��Ƥ��륵�֥롼����ؤΥ�ե���󥹤�ɾ������Τǡ� ���ߤΥ��֥롼����̾���Τ뤳�Ȥʤ��Ƶ��ƤӽФ����Ǥ���褦�ˤʤ�ޤ��� use 5.16.0; my $factorial = sub { my ($x) = @_; return 1 if $x == 1; return($x * __SUB__->( $x - 1 ) ); }; =begin original Subroutines whose names are in all upper case are reserved to the Perl core, as are modules whose names are in all lower case. A subroutine in all capitals is a loosely-held convention meaning it will be called indirectly by the run-time system itself, usually due to a triggered event. Subroutines that do special, pre-defined things include C, C, C plus all functions mentioned in L and L. =end original ̾����������ʸ���Ǥ��륵�֥롼����ϡ� ̾�������ƾ�ʸ���Υ⥸�塼��̾�� (����: pragma �ѤȤ���) ͽ�󤵤�Ƥ���Τ�Ʊ���褦�� Perl �Υ�����ͽ�󤵤�Ƥ��ޤ����¹Ի��˥����ƥ༫�Ȥˤ�ä� (�̾�ϥ��٥�Ȥ�ȥꥬ���Ȥ���) ����Ū�˸ƤӽФ���륵�֥롼����ϡ� ̾����������ʸ���ǽ񤯤Τ���������Ǥ��� �ü�ǡ����餫��������Ƥ��뤳�Ȥ򤹤륵�֥롼����ϡ� C, C, C �ˡ�L �� L �� ��������Ƥ���ؿ����Ƥ�ä�����ΤǤ��� =begin original The C, C, C, C and C subroutines are not so much subroutines as named special code blocks, of which you can have more than one in a package, and which you can B call explicitly. See L =end original The C, C, C, C, C ���֥롼����� ���֥롼����Ȥ��������ü쥳���ɥ֥��å��ǡ�������Ǥ��ĤΥѥå������� ʣ����뤳�Ȥ��Ǥ�������Ū�ˤ� B<�ƤӽФ��ޤ���> �� L �򻲾Ȥ��Ƥ��������� =head2 Private Variables via my() X X X X X X X (my() �ˤ��ץ饤�١����ѿ�) =begin original Synopsis: =end original ����: my $foo; # declare $foo lexically local my (@wid, %get); # declare list of variables local my $foo = "flurp"; # declare $foo lexical, and init it my @oof = @bar; # declare @oof lexical, and init it my $x : Foo = $y; # similar, with an attribute applied =begin original B: The use of attribute lists on C declarations is still evolving. The current semantics and interface are subject to change. See L and L. =end original B<�ٹ�>: C ����Ǥ�°���ꥹ�Ȥλ��ѤϤ��ޤ����ɤ�����Ǥ��� ���ߤ�ʸˡ�ȥ��󥿡��ե��������ѹ�������ǽ��������ޤ��� L �� L �򻲾Ȥ��Ƥ��������� =begin original The C operator declares the listed variables to be lexically confined to the enclosing block, conditional (C), loop (C), subroutine, C, or C'd file. If more than one value is listed, the list must be placed in parentheses. All listed elements must be legal lvalues. Only alphanumeric identifiers may be lexically scoped--magical built-ins like C<$/> must currently be Cized with C instead. =end original C �黻�Ҥϡ������Ϥ�Ǥ���֥��å������ʸ (C)�� �롼��(C)�����֥롼����C�� ���뤤�� C ���줿�ե�����˥쥭��������Ĥ�������� �ѿ���������ޤ�����İʾ�ꥹ�ȥ��åפ���Ƥ�����ˤϡ����Υꥹ�Ȥ� ��̤Ǥ������Ƥ��ʤ���Фʤ�ޤ��� ���٤ƤΥꥹ�����Ǥ������������ͤǤʤ���Фʤ�ޤ��� C<$/> �Τ褦���Ȥ߹����ѿ����������Ǥ� C �� B<�ɽ경> ����ʤ���Фʤ�ʤ��Τ��Ф��� ����ե��٥åȤȿ����ˤ�뼱�̻Ҥϥ쥭������ǥޥ�����ʥ������פˤʤ�ޤ��� =begin original Unlike dynamic variables created by the C operator, lexical variables declared with C are totally hidden from the outside world, including any called subroutines. This is true if it's the same subroutine called from itself or elsewhere--every call gets its own copy. X =end original C ʸ�ˤ�ä����������ưŪ�ѿ��ȤϰۤʤꡢC ��Ȥä� ������줿�쥭�������ѿ��Ϥ����ƤӽФ������֥롼�����ޤᡢ��¦�� �����������ƿ����ޤ��� ��ʬ���Ȥ�Ʊ�����֥롼�����Ƥ�����Ǥ��������Ǥ�--�ġ��θƤӽФ��� ���줾��Υ��ԡ����ͭ���ޤ��� X =begin original This doesn't mean that a C variable declared in a statically enclosing lexical scope would be invisible. Only dynamic scopes are cut off. For example, the C function below has access to the lexical $x variable because both the C and the C occurred at the same scope, presumably file scope. =end original ���Τ��Ȥ���Ū���Ĥ��Ƥ���쥭�����륹�����פ��������Ƥ��� C �ѿ��������ʤ��ʤ�Ȥ������Ȥϰ�̣���ޤ��� ưŪ�ѿ��������ڤ����ޤ��� ���󤲤�ȡ��ʲ��� C �ϥ쥭�������ѿ� $x �˥����������ޤ�; �ʤ��ʤ顢C �� C ��ξ����Ʊ���������פ˸���Ƥ��뤫��Ǥ��� my $x = 10; sub bumpx { $x++ } =begin original An C, however, can see lexical variables of the scope it is being evaluated in, so long as the names aren't hidden by declarations within the C itself. See L. X =end original �������ʤ��� C �ϡ�C ���Ȥ���¦�ˤ�������ˤ�äƱ�����ʤ� ̾���μ�̿��Ʊ��Ĺ������ĥ������פΥ쥭�������ѿ��򸫤뤳�Ȥ��Ǥ��ޤ��� L �򻲾Ȥ��Ƥ��������� X =begin original The parameter list to my() may be assigned to if desired, which allows you to initialize your variables. (If no initializer is given for a particular variable, it is created with the undefined value.) Commonly this is used to name input parameters to a subroutine. Examples: =end original my() ���Ф���ѥ顼�᡼���ꥹ�Ȥˤϡ���˾�ߤȤ�����ѿ����������뤿��� ������Ԥ����Ȥ��Ǥ��ޤ��� (�ѿ����Ф��ƽ���ͤ�Ϳ�����ʤ���С������ѿ���̤����ͤ�Ȥä� ��������ޤ���) ����Ū�ˤ��ε�ǽ�ϥ��֥롼������Ф������ϥѥ�᡼����̾�����դ��뤿��� �Ȥ��Ƥ��ޤ��� ��: $arg = "fred"; # "global" variable $n = cube_root(27); print "$arg thinks the root is $n\n"; fred thinks the root is 3 sub cube_root { my $arg = shift; # name doesn't matter $arg **= 1/3; return $arg; } =begin original The C is simply a modifier on something you might assign to. So when you do assign to variables in its argument list, C doesn't change whether those variables are viewed as a scalar or an array. So =end original C �ϡ����ʤ���������Ԥ������ȹͤ��Ƥ��벿�����Ф��뽤���ҤǤ��� �Ǥ����顢�����ꥹ�Ȥ���ˤ����ѿ����Ф���������Ԥ��Ȥ��ˤ� C �� �������ѿ���������Ȥ��Ƹ����Ƥ���Τ�����Ȥ��Ƹ����Ƥ��뤫�Ȥ��� ���֤��Ѥ��뤳�ȤϤ���ޤ��󡣤Ǥ����顢 my ($foo) = ; # WRONG? my @FOO = ; =begin original both supply a list context to the right-hand side, while =end original ������ξ���Ȥ⤬���դ�ꥹ�ȥ���ƥ����Ȥˤ���Τ��Ф��ơ� my $foo = ; =begin original supplies a scalar context. But the following declares only one variable: =end original ����ϥ����饳��ƥ����Ȥ�Ϳ���ޤ������������ʲ��Τ褦������� �Ԥä���硢��Ĥ��ѿ�������ͭ���Ǥ�: my $foo, $bar = 1; # WRONG =begin original That has the same effect as =end original ����ϰʲ��Τ褦�˽񤤤��Τ�Ʊ�����Ȥˤʤ�ޤ� my $foo; $bar = 1; =begin original The declared variable is not introduced (is not visible) until after the current statement. Thus, =end original ������줿�ѿ��ϡ�����ʸ����λ����ޤǤ�Ƴ������ޤ���(�ԲĻ�� ���֤Ǥ�)�� �������äơ� my $x = $x; =begin original can be used to initialize a new $x with the value of the old $x, and the expression =end original ����ϸŤ� $x ���ͤ�Ȥäƿ����� $x ����������Τ˻Ȥ����Ȥ��Ǥ��ޤ�; ������ my $x = 123 and $x == 123 =begin original is false unless the old $x happened to have the value C<123>. =end original ����ϸŤ� $x ���ͤ����ޤ��� C<123> �Ǥʤ��¤ꡢ������ $x �ˤϵ��� ���ꤵ��ޤ��� =begin original Lexical scopes of control structures are not bounded precisely by the braces that delimit their controlled blocks; control expressions are part of that scope, too. Thus in the loop =end original ���湽ʸ�Υ쥭�����륹�����פϡ���������֥��å�����ڤ��椫�ä��ˤ�ä� ���ʤ�«������뤳�ȤϤ���ޤ���; ���漰��ޤ����������פΰ����Ǥ��� �Ǥ�����ʲ��Υ롼�פǤ� while (my $line = <>) { $line = lc $line; } continue { print $line; } =begin original the scope of $line extends from its declaration throughout the rest of the loop construct (including the C clause), but not beyond it. Similarly, in the conditional =end original $line �Υ������פϤ����������(C�֥��å���ޤ�)�롼�׹�¤�λĤ�� ��ʬ�ޤdz�ĥ����ޤ����������ۤ��뤳�ȤϤ���ޤ��� Ʊ�ͤˡ��ʲ��ξ��ʸ�Ǥ� if ((my $answer = ) =~ /^yes$/i) { user_agrees(); } elsif ($answer =~ /^no$/i) { user_disagrees(); } else { chomp $answer; die "'$answer' is neither 'yes' nor 'no'"; } =begin original the scope of $answer extends from its declaration through the rest of that conditional, including any C and C clauses, but not beyond it. See L for information on the scope of variables in statements with modifiers. =end original $answer �Υ������פϤ������������ʸ�� C �� C �֥��å���ޤ�Ĥ����ʬ�ޤdz�ĥ����ޤ����� �����ۤ��뤳�ȤϤ���ޤ��� �������դ���ʸ�Ǥ��ѿ��Υ������פ˴ؤ������ˤĤ��Ƥ� L �򻲾Ȥ��Ƥ��������� =begin original The C loop defaults to scoping its index variable dynamically in the manner of C. However, if the index variable is prefixed with the keyword C, or if there is already a lexical by that name in scope, then a new lexical is created instead. Thus in the loop X X =end original C �Ϥ���ź�����ѿ����Ф��륹�����פ�ǥե���ȤǤ� C �Τ������ưŪ�ʤ�Τˤ��Ƥ��ޤ��� �������ʤ��顢ź�����ѿ��� C �Ȥ���������ɤ����֤���Ƥ�����硢 �ޤ��ϸ��ߤΥ������פǤ���̾�������Ǥ˥쥭������Ǥ�����ˤϡ� �������쥭�������ѿ�������˺���ޤ��� �Ǥ�����ʲ��Υ롼�פǤ�: X X for my $i (1, 2, 3) { some_function(); } =begin original the scope of $i extends to the end of the loop, but not beyond it, rendering the value of $i inaccessible within C. X X =end original $i �Υ������פϥ롼�פν�ü�ޤdz�ĥ����ޤ����������ۤ��뤳�ȤϤʤ��Τǡ� $i ���ͤ� C ����Ǥϻ��Ȥ��뤳�Ȥ��Ǥ��ʤ��ʤ�ޤ��� X X =begin original Some users may wish to encourage the use of lexically scoped variables. As an aid to catching implicit uses to package variables, which are always global, if you say =end original �桼�����ΰ����ˤϡ��쥭������ʥ������פ��ѿ��λ��Ѥ��夹�뤳�Ȥ� ˾��Ǥ���ͤ⤤��Ǥ��礦�� ��˥������Х�Ǥ���ѥå������ѿ����Ф�����ۤλ��Ѥ���ª���뤳�Ȥ� �������ΤȤ��ơ� use strict 'vars'; =begin original then any variable mentioned from there to the end of the enclosing block must either refer to a lexical variable, be predeclared via C or C, or else must be fully qualified with the package name. A compilation error results otherwise. An inner block may countermand this with C. =end original �Τ褦�ˤ���ȡ�����ʸ���餽���Ϥ�֥��å��ν�ü�ޤǤδ֤��ѿ��λ��Ȥϡ� �쥭�������ѿ����Ф��뻲�Ȥ���C �ޤ��� C �ˤ�� ���������������ʤ���д����ʥѥå�����̾�ǽ������� ̾���Ǥʤ���Фʤ�ޤ��� ����ʳ��Τ�Τ�����ȥ���ѥ��륨�顼��ȯ�����ޤ��� ������оݤȤʤäƤ���֥��å�����¦�ˤ���֥��å��� C �Ȥ����(��¦�Υ֥��å���Ǥ�)�������¤� ���ä����Ȥ��Ǥ��ޤ��� =begin original A C has both a compile-time and a run-time effect. At compile time, the compiler takes notice of it. The principal usefulness of this is to quiet C, but it is also essential for generation of closures as detailed in L. Actual initialization is delayed until run time, though, so it gets executed at the appropriate time, such as each time through a loop, for example. =end original C �ϥ���ѥ�����θ��̤ȼ¹Ի��θ��̤�ξ������äƤ��ޤ��� ����ѥ�����ˤ����Ƥϡ�����ѥ���Ϥ����ѿ���ǧ�����ޤ��� ����δ���Ū�ʼ������� C ���ۤ餻��Ȥ������ȤǤ����� L �Ǿܺ٤򵭽Ҥ��Ƥ��륯��������κ����ˤ�ͭ�ѤǤ��� �ºݤν�����ϼ¹Ի��ޤ��٤餵�졢���Τ��᤿�Ȥ��Х롼�פ��̤��٤� Ŭ�ڤ˼¹Ԥ����ΤǤ��� =begin original Variables declared with C are not part of any package and are therefore never fully qualified with the package name. In particular, you're not allowed to try to make a package variable (or other global) lexical: =end original C �ˤ�ä�������줿�ѿ��ϤɤΥѥå������ΰ����Ǥ�ʤ��� ���Τ���ѥå�����̾��Ȥäƽ�������뤳�ȤϷ褷�Ƥ���ޤ��� �äˡ��ѥå������ѿ�(�⤷���Ϥ���¾�Υ������Х���ѿ�)�� �쥭������ˤ��褦�Ȥ��뤳�Ȥϵ�����Ƥ��ޤ��� my $pack::var; # ERROR! Illegal syntax =begin original In fact, a dynamic variable (also known as package or global variables) are still accessible using the fully qualified C<::> notation even while a lexical of the same name is also visible: =end original �ºݤΤȤ�����ưŪ�ѿ�(�ѥå������ѿ��䥰�����Х��ѿ��Ȥ��� �Τ��Ƥ�����)�ϡ�Ʊ��̾������ä��쥭�����뤬�Ļ�ʾ��֤Ǥ��ä��Ȥ��Ƥ⡢ C<::> ��ˡ��Ȥä�(̾����)�����ʽ�����Ԥ����Ȥˤ�ä� �ޤ�����������ǽ�ʤΤǤ�: package main; local $x = 10; my $x = 20; print "$x and $::x\n"; =begin original That will print out C<20> and C<10>. =end original ������� C<20> �� C<10> ����Ϥ��ޤ��� =begin original You may declare C variables at the outermost scope of a file to hide any such identifiers from the world outside that file. This is similar in spirit to C's static variables when they are used at the file level. To do this with a subroutine requires the use of a closure (an anonymous function that accesses enclosing lexicals). If you want to create a private subroutine that cannot be called from outside that block, it can declare a lexical variable containing an anonymous sub reference: =end original ���Υե�����γ�¦���������餳�Τ褦�ʼ��̻Ҥ򱣤�����ˡ�C �ѿ��� �ե�����κǤ⳰¦�Υ������פ�������뤳�Ȥ��Ǥ��ޤ��� ����ϡ���ǰ�Ȥ��Ƥ� C �ǤΥե������٥�� static �ѿ��Ȼ��Ƥ��ޤ��� ����򥵥֥롼�������¦�ǹԤ��ˤϡ� ����������(�쥭�����륢��������ȼ�ä�̵̾�ؿ�)��Ȥ��ޤ��� �֥��å��dz�¦�Υ֥��å�����ƤӽФ����ȤΤǤ��ʤ��褦�ʥץ饤�١��Ȥ� ���֥롼������ꤿ���ʤ顢̵̾���֥롼����Υ�ե���󥹤� �ݻ�����쥭�������ѿ���������뤳�Ȥ��Ǥ��ޤ�: my $secret_version = '1.001-beta'; my $secret_sub = sub { print $secret_version }; &$secret_sub(); =begin original As long as the reference is never returned by any function within the module, no outside module can see the subroutine, because its name is not in any package's symbol table. Remember that it's not I called C<$some_pack::secret_version> or anything; it's just $secret_version, unqualified and unqualifiable. =end original ���Υ�ե���󥹤��褷�ơ��⥸�塼�����¦�ˤ���ɤ�ʴؿ������ �֤���뤳�Ȥ��ʤ��Τ�Ʊ�ͤˡ���¦�Υ⥸�塼��ϥ��֥롼����� ���뤳�Ȥ��Ǥ��ޤ���; �ʤ��ʤ顢����̾���ϤɤΥѥå������Υ���ܥ� �ơ��֥�ˤ�¸�ߤ��Ƥ��ʤ�����Ǥ��� C<$some_pack::secret_version> �ʤɤμ��ʤ�ȤäƸƤӽФ����Ȥ� B<�Ǥ��ʤ�> �Τ��Ȥ������Ȥ�פ��Ф��Ƥ�������; �����ñ�ʤ� $secret_version �Ǥ��äơ���������뤳�ȤϤʤ��������뤳�ȤϤǤ��ޤ��� =begin original This does not work with object methods, however; all object methods have to be in the symbol table of some package to be found. See L for something of a work-around to this. =end original ����������ϥ��֥������ȥ᥽�åɤȶ���ư����뤳�ȤϤǤ��ޤ���; ���Ƥ� ���֥������ȥ᥽�åɤϡ�ȯ����ǽ�ʲ��餫�Υѥå������Υ���ܥ�ơ��֥�� ¸�ߤ��Ƥ���ɬ�פ�����ޤ��� �������򤹤���ˡ�ˤĤ��Ƥ� L �� ���Ȥ��Ƥ��������� =head2 Persistent Private Variables X X X X X X (��³Ū�ʥץ饤�١����ѿ�) =begin original There are two ways to build persistent private variables in Perl 5.10. First, you can simply use the C feature. Or, you can use closures, if you want to stay compatible with releases older than 5.10. =end original Perl 5.10 �DZ�³Ū�ץ饤�١����ѿ����ۤ���ˤ���Ĥ���ˡ������ޤ��� ����ܤ�ñ�� C ��ǽ��Ȥ����ȤǤ��� ���뤤�ϡ�5.10 ����Ť���꡼���Ȥθߴ�����ݻ��������ʤ顢����������� �Ȥ����ȤǤ��� =head3 Persistent variables via state() (state() �ˤ���³�ѿ�) =begin original Beginning with Perl 5.9.4, you can declare variables with the C keyword in place of C. For that to work, though, you must have enabled that feature beforehand, either by using the C pragma, or by using C<-E> on one-liners (see L). Beginning with Perl 5.16, the C form does not require the C pragma. =end original perl 5.9.4 ���顢C ������� C ������ɤ�Ȥä��ѿ��� ����Ǥ��ޤ��� �������������Ư������ˤϡ�C �ץ饰�ޤ�Ȥ����������Ϻ�Ǥ� C<-E> ��Ȥ����Ȥ�ͽ�ᤳ�ε�ǽ��ͭ���ˤ��ʤ���Фʤ�ޤ��� (L �򻲾Ȥ��Ƥ�������)�� Perl 5.16 ���顢C ������ C �ץ饰�ޤ� ���פˤʤ�ޤ����� =begin original For example, the following code maintains a private counter, incremented each time the gimme_another() function is called: =end original �㤨�С��ʲ��Υ����ɤϥץ饤�١��Ȥʥ����󥿤��������gimme_another() �ؿ��� �ƤӽФ���뤿�Ӥ˥����󥿤����ä����ޤ�: use feature 'state'; sub gimme_another { state $x; return ++$x } =begin original Also, since C<$x> is lexical, it can't be reached or modified by any Perl code outside. =end original �ޤ���C<$x> �ϥ쥭������ʤΤǡ����γ�¦�� Perl �����ɤ��饢���������뤳�Ȥ� �Ǥ��ޤ��� =begin original When combined with variable declaration, simple scalar assignment to C variables (as in C) is executed only the first time. When such statements are evaluated subsequent times, the assignment is ignored. The behavior of this sort of assignment to non-scalar variables is undefined. =end original �ѿ�����ȷ���դ���줿�Ȥ���(C �Τ褦��)C �ѿ��ؤ� ñ��ʥ����������ϰ����ܤ����¹Ԥ���ޤ��� ���θ�ƤӤ���ʸ��ɾ������Ƥ⡢������̵�뤵��ޤ��� �󥹥����ѿ��ؤΤ��μ�������ο����񤤤�̤����Ǥ��� =head3 Persistent variables with closures (����������ˤ���³�ѿ�) =begin original Just because a lexical variable is lexically (also called statically) scoped to its enclosing block, C, or C FILE, this doesn't mean that within a function it works like a C static. It normally works more like a C auto, but with implicit garbage collection. =end original �쥭�������ѿ��Ϥ����Ϥ�֥��å���C��C FILE ��°���� �쥭������(�⤷������Ū)�������פ�°���ޤ�; ���Τ��Ȥ� C �� static ��Ʊ�ͤ� ư���Ȥ������Ȥ��̣���ޤ��� �̾�� C �� auto ��Ʊ���褦��ư��ޤ��������ۤΥ��١������쥯������ ȼ�äƤ��ޤ��� =begin original Unlike local variables in C or C++, Perl's lexical variables don't necessarily get recycled just because their scope has exited. If something more permanent is still aware of the lexical, it will stick around. So long as something else references a lexical, that lexical won't be freed--which is as it should be. You wouldn't want memory being free until you were done using it, or kept around once you were done. Automatic garbage collection takes care of this for you. =end original C �� C++ �ˤ�������������ѿ��ȤϰۤʤꡢPerl �Υ쥭�������ѿ��� ñ�ˤ��Υ������פ���ȴ��������Ȥ�����ͳ�ǡ�ɬ������ꥵ�����뤵��ޤ��� ������äȱ�³Ū�ʤ�Τ����Υ쥭�������ѿ��˴ؤ��Ƥޤ����դ��Ƥ���С� �����α�ޤ�Ǥ��礦�� ����¾�Τ�Τ��쥭�������ѿ��򻲾Ȥ��Ƥ���С����Υ쥭�������ѿ��� ��������ޤ��� -- �����Ƥ�������٤��Ǥ��� ���ʤ��Ϥ����Ȥ������ޤǤϥ��������������Ȥϻפ�ʤ��Ǥ��礦���� �Ȥ�����ä���Τ��ݻ���³�������Ȥ�פ�ʤ��Ǥ��礦�� ���ʤ��Τ���˼�ư���١������쥯����󤬤����Ԥ��ޤ��� =begin original This means that you can pass back or save away references to lexical variables, whereas to return a pointer to a C auto is a grave error. It also gives us a way to simulate C's function statics. Here's a mechanism for giving a function private variables with both lexical scoping and a static lifetime. If you do want to create something like C's static variables, just enclose the whole function in an extra block, and put the static variable outside the function but in the block. =end original ����ϤĤޤꡢ�쥭�������ѿ����Ф����ե���󥹤��֤�������¸������ ���뤳�Ȥ��Ǥ���Ȥ������ȤǤ�; ���� C �� auto �ѿ����Ф���ݥ��󥿤� �֤����Ȥϥ��顼�Ȥʤ�ޤ��� �쥭�������ѿ��Ϥޤ���C �δؿ��� static ���ѿ��Υ��ߥ�졼�Ȥ�Ԥ��ޤ��� �ʲ�����ϥ쥭�����륹�����פ���Ĥ�Ʊ���� static �ʼ�̿����Ĵؿ��� �ץ饤�١��Ȥ��ѿ��Ǥ��� C �� static �ѿ��Τ褦�ʤ�Τ��ꤿ���Ȥ����ΤǤ���С� �ؿ����Τ򤵤�˥֥��å��ǰϤ�Ǥ�ꡢstatic �ѿ���֥��å�����¦�ǡ� ���Ĵؿ��γ�¦�ξ��ˤ����Ƥ��ޤ��� { my $secret_val = 0; sub gimme_another { return ++$secret_val; } } # $secret_val now becomes unreachable by the outside # world, but retains its value between calls to gimme_another =begin original If this function is being sourced in from a separate file via C or C, then this is probably just fine. If it's all in the main program, you'll need to arrange for the C to be executed early, either by putting the whole block above your main program, or more likely, placing merely a C code block around it to make sure it gets executed before your program starts to run: =end original ���δؿ��� C �� C ���̤����̤���Ω�����ե����뤫�� �����ޤ줿��硢����ϤȤƤ����Ω�Ĥ��ȤǤ��礦�� �⤷���줬���٤ƥᥤ��ץ���������ˤ���ΤǤ���С� �֥��å����Τ�ᥤ��ץ������������֤�����(�����餫���ޤ���������Ǥ���) �ץ�����ब�¹Ԥ����������˼¹Ԥ���뤳�Ȥ��ݾڤ���Ƥ��� BEGIN �����ɥ֥��å�������֤��褦�ˤ��ơ�C �����˼¹Ԥ���褦�� �ѹ�����ɬ�פ�����Ǥ��礦: BEGIN { my $secret_val = 0; sub gimme_another { return ++$secret_val; } } =begin original See L about the special triggered code blocks, C, C, C, C and C. =end original ���̤ʥȥꥬ�������ɥ֥��å��Ǥ��� C, C, C, C �� �Ĥ��Ƥ� L �򻲾Ȥ��Ƥ��������� =begin original If declared at the outermost scope (the file scope), then lexicals work somewhat like C's file statics. They are available to all functions in that same file declared below them, but are inaccessible from outside that file. This strategy is sometimes used in modules to create private variables that the whole module can see. =end original �Ǥ⳰¦�Υ�������(�ե����륹������)��������줿�ΤǤ���С� �쥭�������ѿ��� C �Υե������ static �ʤ�Τ�Ʊ���褦�˿����񤤤ޤ��� Ʊ���ե�����Ρ�����θ�ˤ������Ƥδؿ����黲�Ȳ�ǽ�Ǥ���ޤ����� ���Υե�����γ�¦���黲�Ȥ��뤳�ȤϤǤ��ޤ��� ������ά�ϥ⥸�塼�����ǥ⥸�塼�����Τ��鸫���� �ץ饤�١��Ȥ��ѿ����뤿��˻Ȥ��ޤ��� =head2 Temporary Values via local() X X X X X (local() ��Ȥä����Ū����) =begin original B: In general, you should be using C instead of C, because it's faster and safer. Exceptions to this include the global punctuation variables, global filehandles and formats, and direct manipulation of the Perl symbol table itself. C is mostly used when the current value of a variable must be visible to called subroutines. =end original B<�ٹ�>: ����Ū�ˤϡ�C �ǤϤʤ�C ��Ȥ��٤��Ǥ�; �ʤ��ʤ顢������� �ۤ����᤯������������Ǥ��� �����㳰�ˤϡ��������Х�ʶ������ѿ�(punctuation variable)���������Х� �ե�����ϥ�ɥ롢�ե����ޥåȡ������� Perl �Υ���ܥ�ơ��֥뼫�Ȥ��Ф��� ľ�ܤ����ޤޤ�ޤ��� C �ϤۤȤ�ɤξ�硢�ѿ��θ��ߤ��ͤ��ƤӽФ��줿���֥롼����� �Ф��ƲĻ�ˤ��ʤ���Фʤ�ʤ����˻Ȥ��ޤ��� =begin original Synopsis: =end original ����: =begin original # localization of values =end original # �ͤΥ������벽 =begin original local $foo; # make $foo dynamically local local (@wid, %get); # make list of variables local local $foo = "flurp"; # make $foo dynamic, and init it local @oof = @bar; # make @oof dynamic, and init it =end original local $foo; # $foo ��ưŪ�˥�������ˤ��� local (@wid, %get); # �ѿ��Υꥹ�Ȥ��������ˤ��� local $foo = "flurp"; # $foo ��ưŪ�ˤ��ơ���������� local @oof = @bar; # @oof ��ưŪ�ˤ��ơ���������� =begin original local $hash{key} = "val"; # sets a local value for this hash entry delete local $hash{key}; # delete this entry for the current block local ($cond ? $v1 : $v2); # several types of lvalues support # localization =end original local $hash{key} = "val"; # ���Υϥå��奨��ȥ�˥���������ͤ������ delete local $hash{key}; # ���ߤΥ֥��å��Ǥ��Υ���ȥ���� local ($cond ? $v1 : $v2); # �����Ĥ��μ���κ����ͤϥ������벽�� # �б����Ƥ��� =begin original # localization of symbols =end original # ����ܥ�Υ������벽 =begin original local *FH; # localize $FH, @FH, %FH, &FH ... local *merlyn = *randal; # now $merlyn is really $randal, plus # @merlyn is really @randal, etc local *merlyn = 'randal'; # SAME THING: promote 'randal' to *randal local *merlyn = \$randal; # just alias $merlyn, not @merlyn etc =end original local *FH; # $FH, @FH, %FH, &FH ... ��������벽 local *merlyn = *randal; # ������ $merlyn �ϼºݤˤ� $randal������� # @merlyn �ϼºݤˤ� @randal���ʤ� local *merlyn = 'randal'; # ��Ʊ�͡�: 'randal' �� *randal �ˤ��� local *merlyn = \$randal; # ñ�� $merlyn ����̾�� @merlyn �ʤɤǤϤʤ� =begin original A C modifies its listed variables to be "local" to the enclosing block, C, or C--and to I. A C just gives temporary values to global (meaning package) variables. It does I create a local variable. This is known as dynamic scoping. Lexical scoping is done with C, which works more like C's auto declarations. =end original C �ϡ������˼�ä����Υꥹ������ѿ���(local() ��Ϥ�)�֥��å� (���뤤�ϡ����֥롼����, C��C)�ȡ�B<���Υ֥��å���� �ƤӽФ��줿���ƤΤ��> �˥�������ʤ�Τˤ��ޤ��� C ��ñ�˥������Х��ѿ�(��ѥå������ѿ�)�˰��Ū���ͤ�Ϳ��������Ǥ��� ����ϥ��������ѿ��� I<���ޤ���>�� �����ưŪ�������פȤ����Τ��Ƥ��ޤ��� �쥭�����륹�����פ� C ��ȤäƹԤ�졢����� C �� ��ư�ѿ�����Τ褦�� Ư���ޤ��� =begin original Some types of lvalues can be localized as well: hash and array elements and slices, conditionals (provided that their result is always localizable), and symbolic references. As for simple variables, this creates new, dynamically scoped values. =end original �����Ĥ��μ���κ����ͤ�������벽�Ǥ��ޤ�: �ϥå������������Ǥȥ��饤���� ���ʸ(���η�̤���˥������벽��ǽ�ʤ��)������ܥ�å���ե���󥹡� ñ���ѿ��˴ؤ��Ƥϡ�����Ͽ�������ưŪ�������פ�����ͤ���ޤ��� =begin original If more than one variable or expression is given to C, they must be placed in parentheses. This operator works by saving the current values of those variables in its argument list on a hidden stack and restoring them upon exiting the block, subroutine, or eval. This means that called subroutines can also reference the local variable, but not the global one. The argument list may be assigned to if desired, which allows you to initialize your local variables. (If no initializer is given for a particular variable, it is created with an undefined value.) =end original C ���Ф�����İʾ���ѿ���ɽ����Ϳ����Τʤ�С��������ѿ��ϳ�̤� �����äƤ����ʤ���Фʤ�ޤ��� ���α黻�Ҥϰ����ꥹ�Ȥˤ����ѿ��Υ����Ȥ��ͤ򱣤줿�����å�����¸���� �֥��å��䥵�֥롼����eval ����ȴ����Ȥ��ˤ����ͤ��������뤳�Ȥˤ�ä� ư��Ƥ��ޤ��� ����ϤĤޤꡢ�ƤӽФ��줿���֥롼���󤫤����������ѿ��� ���Ȥ��뤳�Ȥ��Ǥ��뤱��ɤ⡢�������Х�ʤ�Τ򸫤뤳�Ȥ� �Ǥ��ʤ��Ȥ������ȤǤ��� �����ꥹ�Ȥˤϡ����ߤ˱����ƥꥹ����Υ��������ѿ����������뤿��� ������Ԥ����Ȥ��Ǥ��ޤ��� (����������ѿ����Ф��ƽ���ͤ�Ϳ�����ʤ��ä����ˤϡ������ѿ���̤����ͤ� ȼ�ä���������ޤ���) =begin original Because C is a run-time operator, it gets executed each time through a loop. Consequently, it's more efficient to localize your variables outside the loop. =end original C �ϼ¹Ի��黻�ҤʤΤǡ��롼�פ��̤��٤˼¹Ԥ���ޤ��� ���ߤ� Perl �ϥ���λ��Ѥ˴ؤ��Ʋ�������Ƥ��ޤ����� ��̤Ȥ��ơ��롼�פγ�¦���ѿ�����������ۤ�������Ψ���ɤ��ΤǤ��� =head3 Grammatical note on local() X (local() ��ʸˡŪ����) =begin original A C is simply a modifier on an lvalue expression. When you assign to a Cized variable, the C doesn't change whether its list is viewed as a scalar or an array. So =end original C �Ϻ����ͤ��Ф���ñ�ʤ뽤���ҤǤ��� �ɽ경���줿�ѿ���������Ԥä��Ȥ���C �Ϥ��Υꥹ�Ȥ�������Ȥ��� �����Ƥ���Τ�����Ȥ��Ƹ����Ƥ��뤫�Ȥ������Ȥ��Ѥ��뤳�ȤϤ���ޤ��� �Ǥ����顢 local($foo) = ; local @FOO = ; =begin original both supply a list context to the right-hand side, while =end original ������ξ���Ȥ⤬���դ�ꥹ�ȥ���ƥ����Ȥˤ���Τ��Ф��ơ� local $foo = ; =begin original supplies a scalar context. =end original ����ϥ����饳��ƥ����Ȥ�Ϳ���ޤ�. =head3 Localization of special variables X (�ü��ѿ��Υ������벽) =begin original If you localize a special variable, you'll be giving a new value to it, but its magic won't go away. That means that all side-effects related to this magic still work with the localized value. =end original �ü��ѿ���������벽����ȡ�����˿������ͤ�������ޤ������ü쵡ǽ�� �ʤ��ʤ�ޤ��� ����ϡ������ü쵡ǽ�˴ط��������Ƥ������Ѥϥ������벽���줿�ͤ��Ф��Ƥ� Ư���Ȥ������Ȥ��̣���ޤ��� =begin original This feature allows code like this to work : =end original ���ε�ǽ�ϰʲ��Τ褦�ʥ����ɤ�ư���褦�ˤ��ޤ�: # Read the whole contents of FILE in $slurp { local $/ = undef; $slurp = ; } =begin original Note, however, that this restricts localization of some values ; for example, the following statement dies, as of perl 5.9.0, with an error I, because the $1 variable is magical and read-only : =end original ������������Ϥ����Ĥ����ͤΥ������벽�����¤��뤳�Ȥ����դ��Ƥ�������; �㤨�С��ʲ���ʸ�ϡ�perl 5.9.0 ����ϡ� I �Ȥ������顼�� die ���ޤ�; �ʤ��ʤ� $1 �ѿ��ϥޥ�������ɤ߹������Ѥ�����Ǥ�: local $1 = 2; =begin original One exception is the default scalar variable: starting with perl 5.14 C will always strip all magic from $_, to make it possible to safely reuse $_ in a subroutine. =end original ��Ĥ��㳰�ϡ��ǥե���ȥ������ѿ��Ǥ�: perl 5.14 ���顢���֥롼������� ������ $_ ������ѤǤ���褦�ˡ�C �Ͼ�� ���ƤΥޥ��å���������ޤ��� =begin original B: Localization of tied arrays and hashes does not currently work as described. This will be fixed in a future release of Perl; in the meantime, avoid code that relies on any particular behaviour of localising tied arrays or hashes (localising individual elements is still okay). See L for more details. X =end original B<�ٹ�>: tie ���줿����ȥϥå���Υ������벽�ϸ��ߤΤȤ��� ���Ҥ��줿�Ȥ����ư��ޤ��� ����� Perl �ξ���Υ�꡼���ǽ�������ޤ�; ���̤δ֤ϡ�tie ���줿�����ϥå���Υ������벽�ˤ��ɤΤ褦�� �����񤤤ˤ��¸���ʤ��褦�ʥ����ɤˤ��Ƥ������� (�ġ������ǤΥ������벽�����ꤢ��ޤ���)�� ����ʤ�ܺ٤ˤĤ��Ƥ� L �� ���Ȥ��Ƥ��������� X =head3 Localization of globs X X (�����֤Υ������벽) =begin original The construct =end original �ʲ��Τ褦�ʹ�¤�� local *name; =begin original creates a whole new symbol table entry for the glob C in the current package. That means that all variables in its glob slot ($name, @name, %name, &name, and the C filehandle) are dynamically reset. =end original ���ߤΥѥå������ǥ����� C �Τ���δ����˿���������ܥ�ơ��֥� ����ȥ��������ޤ��� ����ϡ����Υ����֥����åȤ��������Ƥ��ѿ� ($name, @name, %name, &name, C �ե�����ϥ�ɥ�) ��ưŪ�˥ꥻ�åȤ���뤳�Ȥ��̣���ޤ��� =begin original This implies, among other things, that any magic eventually carried by those variables is locally lost. In other words, saying C will not have any effect on the internal value of the input record separator. =end original ������äˡ� �ǽ�Ū�ˤ������ѿ��ˤ�äƤ⤿�餵���ޥ��å��϶ɽ�Ū�ˤ� �����뤳�Ȥ��̣���ޤ��� ����������ȡ�C �Ȥ��Ƥ⡢���ϥ쥳���ɥ��ѥ졼���������� �ͤˤϲ��αƶ���Ϳ���ʤ��Ȥ������ȤǤ��� =head3 Localization of elements of composite types X X X (ʣ�緿�����ǤΥ������벽) =begin original It's also worth taking a moment to explain what happens when you Cize a member of a composite type (i.e. an array or hash element). In this case, the element is Cized I. This means that when the scope of the C ends, the saved value will be restored to the hash element whose key was named in the C, or the array element whose index was named in the C. If that element was deleted while the C was in effect (e.g. by a C from a hash or a C of an array), it will spring back into existence, possibly extending an array and filling in the skipped elements with C. For instance, if you say =end original �������Υ��С�(���Ȥ��������ϥå��������)�ζɽ경�����Ȥ��� �ɤ��ʤ뤫���������ޤ��礦�� ���ξ�硢�������Ǥ� B<̾���ˤ�ä�> �ɽ경���Ԥ��ޤ��� ����ϤĤޤꡢC �Υ������פ�����ä��Ȥ��ˡ�C ��̾���� �Ȥ��Ƥ�����������ĥϥå�������Ǥ� C ��̾�����Ȥ��Ƥ��� �������Ǥ˴ؤ�����¸����Ƥ����ͤ���������Ȥ������ȤǤ��� C �����̤���äƤ���Ȥ����Ǥ������ä����Ǥ�������줿��� (�㤨�Хϥå�����Ф��� delete() ��Ȥ��Ȥ�������Ф��� C��Ȥ�)�ˡ�C ��ͭ���ϰϤ�ȴ�����Ȥ����� ������줿���Ǥ����褷������γ�ĥ�ȳ�ĥ����ʬ�����Ǥ��ͤ� C �ˤ���Ȥ������Ȥ�Ԥ��ޤ����㤨�аʲ��Τ褦�ʾ�硢 %hash = ( 'This' => 'is', 'a' => 'test' ); @ary = ( 0..5 ); { local($ary[5]) = 6; local($hash{'a'}) = 'drill'; while (my $e = pop(@ary)) { print "$e . . .\n"; last unless $e > 3; } if (@ary) { $hash{'only a'} = 'test'; delete $hash{'a'}; } } print join(' ', map { "$_ $hash{$_}" } sort keys %hash),".\n"; print "The array has ",scalar(@ary)," elements: ", join(', ', map { defined $_ ? $_ : 'undef' } @ary),"\n"; =begin original Perl will print =end original Perl �ϰʲ��Τ褦�ʽ��Ϥ򤷤ޤ��� 6 . . . 4 . . . 3 . . . This is a test only a test. The array has 6 elements: 0, 1, 2, undef, undef, 5 =begin original The behavior of local() on non-existent members of composite types is subject to change in future. =end original ʣ�緿��¸�ߤ��Ƥ��ʤ����С����Ф��� local() �ο����񤤤� �����ѹ������ͽ��Ǥ��� =head3 Localized deletion of elements of composite types X X X X =begin original You can use the C and C constructs to delete a composite type entry for the current block and restore it when it ends. They return the array/hash value before the localization, which means that they are respectively equivalent to =end original ���ߤΥ֥��å����餢��ʣ�緿����ȥ�������ƥ֥��å��ν�λ���� �������뤿��ˡ�C ����� C ��ʸ��Ȥ��ޤ��� �����ϥ������벽�������������/�ϥå�����ͤ��֤��Τǡ��ʲ��Ϥ��줾�� �����Ǥ�: do { my $val = $array[$idx]; local $array[$idx]; delete $array[$idx]; $val } =begin original and =end original ����� do { my $val = $hash{key}; local $hash{key}; delete $hash{key}; $val } =begin original except that for those the C is scoped to the C block. Slices are also accepted. =end original â�� C �� C �֥��å��Υ������פǤ��� ���饤��������դ����ޤ��� my %hash = ( a => [ 7, 8, 9 ], b => 1, ) { my $a = delete local $hash{a}; # $a is [ 7, 8, 9 ] # %hash is (b => 1) { my @nums = delete local @$a[0, 2] # @nums is (7, 9) # $a is [ undef, 8 ] $a[0] = 999; # will be erased when the scope ends } # $a is back to [ 7, 8, 9 ] } # %hash is back to its original state =head2 Lvalue subroutines X X (�����ͥ��֥롼����) =begin original B: Lvalue subroutines are still experimental and the implementation may change in future versions of Perl. =end original B<�ٹ�>: �����ͥ��֥롼�����̤���¸�Ū��ǽ�Ǥ��ꡢ ����ΥС������� Perl �Ǥϼ������ѹ�����뤫�⤷��ޤ��� =begin original It is possible to return a modifiable value from a subroutine. To do this, you have to declare the subroutine to return an lvalue. =end original ���֥롼���󤫤顢�ѹ���ǽ���ͤ��֤����Ȥ���ǽ�Ǥ��� �������뤿��ˤϡ����֥롼���󤬺����ͤ��֤��褦��������ʤ���Фʤ�ޤ��� my $val; sub canmod : lvalue { $val; # or: return $val; } sub nomod { $val; } canmod() = 5; # assigns to $val nomod() = 5; # ERROR =begin original The scalar/list context for the subroutine and for the right-hand side of assignment is determined as if the subroutine call is replaced by a scalar. For example, consider: =end original ���֥롼����ȡ������α�¦�Υ�����/�ꥹ�ȥ���ƥ����Ȥ� ���֥롼����ƤӽФ�����������֤�������줿���Τ褦�ˤ��� ���ꤵ��ޤ��� ��Ȥ��ơ��ʲ���ͤ����: data(2,3) = get_data(3,4); =begin original Both subroutines here are called in a scalar context, while in: =end original ξ���Υ��֥롼����ϥ����饳��ƥ����ȤǸƤӽФ��졢����: (data(2,3)) = get_data(3,4); =begin original and in: =end original �ڤ�: (data(2),data(3)) = get_data(3,4); =begin original all the subroutines are called in a list context. =end original �ˤĤ��Ƥ����ƤΥ��֥롼����ϥꥹ�ȥ���ƥ����ȤǸƤӽФ���ޤ��� =over 4 =item Lvalue subroutines are EXPERIMENTAL =begin original They appear to be convenient, but there is at least one reason to be circumspect. =end original ����������ʤ褦�Ǥ��������Ťˤʤ�٤����ʤ��Ȥ��Ĥ���ͳ������ޤ��� =begin original They violate encapsulation. A normal mutator can check the supplied argument before setting the attribute it is protecting, an lvalue subroutine never gets that chance. Consider; =end original ����ϥ��ץ��벽�˰�ȿ���Ƥ��ޤ��� �̾�� mutator �ϡ����Ȥ��ݸ�Ƥ���°���˥��åȤ������� ����������å��Ǥ��ޤ����� �����ͥ��֥롼����ˤϤ��ε���Ϥ���ޤ��� �ʲ���ͤ��ƤߤƤ�������; my $some_array_ref = []; # protected by mutators ?? sub set_arr { # normal mutator my $val = shift; die("expected array, you supplied ", ref $val) unless ref $val eq 'ARRAY'; $some_array_ref = $val; } sub set_arr_lv : lvalue { # lvalue mutator $some_array_ref; } # set_arr_lv cannot stop this ! set_arr_lv() = { a => 1 }; =back =head2 Passing Symbol Table Entries (typeglobs) X X<*> (����ܥ�ơ��֥�Υ���ȥ���Ϥ�(��������)) =begin original B: The mechanism described in this section was originally the only way to simulate pass-by-reference in older versions of Perl. While it still works fine in modern versions, the new reference mechanism is generally easier to work with. See below. =end original B<�ٹ�>: ���Υ�����������������Ƥ�����Ȥߤϡ��Ť��С������� Perl �� �����ƻ����Ϥ��򥷥ߥ�졼�Ȥ��뤿���ͣ�����ˡ�Ǥ����� ����ϸ��ߤǤ�Ȥ����Ȥ��Ǥ���ΤǤ�������������ե���󥹤λ��Ȥߤ� ��������ñ�˹Ԥ��ޤ�����������򻲾Ȥ��Ƥ��������� =begin original Sometimes you don't want to pass the value of an array to a subroutine but rather the name of it, so that the subroutine can modify the global copy of it rather than working with a local copy. In perl you can refer to all objects of a particular name by prefixing the name with a star: C<*foo>. This is often known as a "typeglob", because the star on the front can be thought of as a wildcard match for all the funny prefix characters on variables and subroutines and such. =end original ���֥롼�����Ϥ��줿����Υ�������ʥ��ԡ��ǤϤʤ��ƥ������Х�� ��Τ��ѹ����Ǥ���褦�ˡ����֥롼������Ф���������ͤǤϤʤ� �����̾�����Ϥ������ʤ뤳�Ȥ⤢��Ǥ��礦�� perl �ˤ����Ƥϡ������ C<*foo> �Τ褦�˥������ꥹ����Ȥä� �Ԥ����Ȥ��Ǥ��ޤ��� ����������֤��줿�������ꥹ�����ѿ��䥵�֥롼����ʤɤ��Ф��ƻȤ��� ���֥���饯�������Ƥ˥ޥå�����磻��ɥ����ɤȤ��Ƥߤʤ����Ȥ� �Ǥ���Τǡ��ȷ������֡ɤȤ��Ƥ褯�Τ��Ƥ��ޤ��� =begin original When evaluated, the typeglob produces a scalar value that represents all the objects of that name, including any filehandle, format, or subroutine. When assigned to, it causes the name mentioned to refer to whatever C<*> value was assigned to it. Example: =end original �������֤�ɾ�����줿�Ȥ��ˤ���̾����������ƤΥ��֥�������(�ե�����ϥ�ɥ롢 �ե����ޥåȡ����֥롼�����ޤޤ�ޤ�)��ɽ���������ͤ��������ޤ��� �������Ԥ�줿�Ȥ���C<*> ������������Τ�ȿ�Ǥ���褦�ˤʤ�ޤ��� ��: sub doubleary { local(*someary) = @_; foreach $elem (@someary) { $elem *= 2; } } doubleary(*foo); doubleary(*bar); =begin original Scalars are already passed by reference, so you can modify scalar arguments without using this mechanism by referring explicitly to C<$_[0]> etc. You can modify all the elements of an array by passing all the elements as scalars, but you have to use the C<*> mechanism (or the equivalent reference mechanism) to C, C, or change the size of an array. It will certainly be faster to pass the typeglob (or reference). =end original ������ϴ��˻����Ϥ�����Ƥ���Τǡ��ۤ� C<$_[0]> �ʤɤǻ��Ȥ��� ���ε�����Ȥ�ʤ��Ƥ⥹����������ѹ����뤳�Ȥ��Ǥ��ޤ��� ���Ƥ����Ǥ�������Ȥ����Ϥ��줿��������ǤϤ��٤� �ѹ����뤳�Ȥ��Ǥ��ޤ�����C��C���⤷��������Υ������� �ѹ����뤿��ˤ� C<*> ����(�⤷����Ʊ���Υ�ե���󥹵���)�� �Ȥ�ɬ�פ�����ޤ��� ����Ϸ�������(�⤷���ϥ�ե����)���Ϥ��Τ�μ¤˹�®�ˤ���Ǥ��礦�� =begin original Even if you don't want to modify an array, this mechanism is useful for passing multiple arrays in a single LIST, because normally the LIST mechanism will merge all the array values so that you can't extract out the individual arrays. For more on typeglobs, see L. =end original ������ѹ���˾�ޤʤ��Ȥ��Ƥ⡢���ε�����ñ��Υꥹ�Ȥ���ˤ���ʣ���� �ꥹ�Ȥ��Ϥ��Τ������Ǥ�; �ʤ��ʤ顢�̾�ϥꥹ�ȵ����Ϥ��٤Ƥ�������ͤ� ��礷�Ƥ��ޤ��Τ���Ω�����������Ф����Ȥ��Ǥ��ʤ�����Ǥ��� �������֤ˤĤ��Ƥϡ� L �⻲�Ȥ��Ƥ��������� =head2 When to Still Use local() X X (���Ǥ� local() ��Ȥ��Ȥ�) =begin original Despite the existence of C, there are still three places where the C operator still shines. In fact, in these three places, you I use C instead of C. =end original C ������ˤ�ؤ餺�����Ǥ� C �黻�Ҥ�Ȥ��٤���꤬�����ꤢ��ޤ��� �ºݤˤϤ��λ�����ˤ����Ƥϡ�C �ǤϤʤ���B<ɬ��> C �� �Ȥ�ʤ���Фʤ�ޤ��� =over 4 =item 1. =begin original You need to give a global variable a temporary value, especially $_. =end original �������Х��ѿ�(�ä� C<$_>) �˴ؤ��ơ����Ū���ͤ�Ϳ�������Ȥ��� =begin original The global variables, like C<@ARGV> or the punctuation variables, must be Cized with C. This block reads in F, and splits it up into chunks separated by lines of equal signs, which are placed in C<@Fields>. =end original C<@ARGV> ��������ѿ�(punctuation variables)�Τ褦�ʥ������Х��ѿ��Ǥϡ� �ɽ경�Τ���� C ��Ȥ�ʤ���Фʤ�ޤ��� �ʲ��Υ֥��å��� F ���ɤ߹��ߡ����������ȤäƹԤβ���ʬ�䤷�� ���η�̤� C<@Fields> �˳�Ǽ���ޤ��� { local @ARGV = ("/etc/motd"); local $/ = undef; local $_ = <>; @Fields = split /^\s*=+\s*$/; } =begin original It particular, it's important to Cize $_ in any routine that assigns to it. Look out for implicit assignments in C conditionals. =end original �ä˽��פʤΤϡ�Ǥ�դΥ롼�������� $_ ��ɽ경����������Ф��� �������뤳�ȤǤ��� C ʸ�Ǥΰ���Ū�����������դ��Ƥ��������� =item 2. =begin original You need to create a local file or directory handle or a local function. =end original ��������ʥե�����ϥ�ɥ��ǥ��쥯�ȥ�ϥ�ɥ롢 �⤷���ϥ�������ؿ����������ɬ�פ������硣 =begin original A function that needs a filehandle of its own must use C on a complete typeglob. This can be used to create new symbol table entries: =end original �ؿ��˸�ͭ�Υե�����ϥ�ɥ뤬ɬ�פʴؿ��ϡ������ʷ������֤�Ȥä� C ��Ȥ�ʤ���Фʤ�ޤ��� ����ˤ�äơ�����������ܥ�ơ��֥�Υ���ȥ꤬��������ޤ�: sub ioqueue { local (*READER, *WRITER); # not my! pipe (READER, WRITER) or die "pipe: $!"; return (*READER, *WRITER); } ($head, $tail) = ioqueue(); =begin original See the Symbol module for a way to create anonymous symbol table entries. =end original ̵̾����ܥ�ơ��֥������������ˡ�ˤĤ��Ƥϡ�Symbol �⥸�塼��� ���Ȥ��Ƥ��������� =begin original Because assignment of a reference to a typeglob creates an alias, this can be used to create what is effectively a local function, or at least, a local alias. =end original �������֤��Ф����ե���󥹤������ϥ����ꥢ������������Τǡ� �ʲ�����Ǥϸ���Ū�˥�������ؿ�(���뤤�Ͼ��ʤ��Ȥ�������륨���ꥢ��)�� ��������Τ˻Ȥ����Ȥ��Ǥ��ޤ��� { local *grow = \&shrink; # only until this block exits grow(); # really calls shrink() move(); # if move() grow()s, it shrink()s too } grow(); # get the real grow() again =begin original See L for more about manipulating functions by name in this way. =end original �������ä�������ǡ�̾���ˤ�äƴؿ���������ˡ�˴ؤ��Ƥξܺ٤� L �򻲾Ȥ��Ƥ��������� =item 3. =begin original You want to temporarily change just one element of an array or hash. =end original �����ϥå���Τ������Ǥ�������Ū���ѹ���������硣 =begin original You can Cize just one element of an aggregate. Usually this is done on dynamics: =end original ��Ĥ����Ǥ�����ɽ경���뤳�Ȥ���ǽ�Ǥ��� �̾�Ϥ����ưŪ�˹Ԥ��ޤ��� { local $SIG{INT} = 'IGNORE'; funct(); # uninterruptible } # interruptibility automatically restored here =begin original But it also works on lexically declared aggregates. Prior to 5.005, this operation could on occasion misbehave. =end original ������������ϥ쥭�������ѿ��Ǥ��äƤ�ư��ޤ��� 5.005 ������Τ�ΤǤϡ��������ϴְ�ä������ˤʤ��ǽ��������ޤ����� =back =head2 Pass by Reference X X X (�����Ϥ�) =begin original If you want to pass more than one array or hash into a function--or return them from it--and have them maintain their integrity, then you're going to have to use an explicit pass-by-reference. Before you do that, you need to understand references as detailed in L. This section may not make much sense to you otherwise. =end original �⤷�������ϥå������İʾ�ؿ����Ϥ������Ȥ��ؿ������֤������� �ͤ��Ƥ��ơ�Ʊ���ˤ��������ʾ��֤ǰ��������Ȥ����ΤǤ���С� ����Ū�˻����Ϥ���Ȥ�ɬ�פ�����Ǥ��礦�� �����Ԥ����ˡ�L ����������Ƥ����ե���󥹤����򤹤� ɬ�פ�����ޤ��� ���Υ��������Ǥϲ������������褦�ʤ��ȤϤ��ޤ��� =begin original Here are a few simple examples. First, let's pass in several arrays to a function and have it C all of then, returning a new list of all their former last elements: =end original ���Ĥ�ñ������󤲤ޤ��礦�� �ޤ��ǽ�ˡ�����ؿ��˴��Ĥ���������Ϥ��� ���Ƥ�������Ф��� C ��Ԥäư����Ȥ��Ƽ�����ä������ ���줾��κǸ�����Ǥ���ʤ뿷�����ꥹ�Ȥ��֤��Ȥ������Ȥ� �ͤ��Ƥߤޤ��礦�� @tailings = popmany ( \@a, \@b, \@c, \@d ); sub popmany { my $aref; my @retlist = (); foreach $aref ( @_ ) { push @retlist, pop @$aref; } return @retlist; } =begin original Here's how you might write a function that returns a list of keys occurring in all the hashes passed to it: =end original �ʲ�����ϡ������Ȥ����Ϥ��줿���ƤΥϥå���ˤ��륭���Υꥹ�Ȥ� �֤��ؿ��Ǥ�: @common = inter( \%foo, \%bar, \%joe ); sub inter { my ($k, $href, %seen); # locals foreach $href (@_) { while ( $k = each %$href ) { $seen{$k}++; } } return grep { $seen{$_} == @_ } keys %seen; } =begin original So far, we're using just the normal list return mechanism. What happens if you want to pass or return a hash? Well, if you're using only one of them, or you don't mind them concatenating, then the normal calling convention is ok, although a little expensive. =end original �ȤϤ�����ΤΡ�������̾�Υꥹ�Ȥ��֤�������ȤäƤ��ޤ��� �ϥå�����Ϥ����Ȥ����ꡢ�ϥå�����֤����Ȥ���Ȳ���������ΤǤ��礦��? �����Ǥ��������ΰ�Ĥ�����Ȥ�������Ϣ�뤬�Ԥ��뤳�Ȥ򵤤ˤ��ʤ���� �̾�θƤӽФ������Ʊ�����ȤǤ�; �������������⤯�Ĥ��ޤ��� =begin original Where people get into trouble is here: =end original ���Τ褦�˽񤯤Τϥȥ�֥�Τ�ȤǤ�: (@a, @b) = func(@c, @d); or (%a, %b) = func(%c, %d); =begin original That syntax simply won't work. It sets just C<@a> or C<%a> and clears the C<@b> or C<%b>. Plus the function didn't get passed into two separate arrays or hashes: it got one long list in C<@_>, as always. =end original �����ι�ʸ��ñ��ˤ��ޤ������ޤ��� ����ͤ� C<@a>�� C<%a>�����˥��åȤ���ơ�C<@b> �� C<%b> �ϥ��ꥢ����ޤ��� ����˲ä������δؿ��ϰ����Ȥ�����Ĥ�������ĤΥϥå����������ޤ���: �������ΤϾ�� C<@_> �˳�Ǽ����Ƥ���(��Ĥΰ��������Ƥ�Ϣ�뤵�줿)��Ĥ� Ĺ���ꥹ�ȤʤΤǤ��� =begin original If you can arrange for everyone to deal with this through references, it's cleaner code, although not so nice to look at. Here's a function that takes two array references as arguments, returning the two array elements in order of how many elements they have in them: =end original ������ե���󥹷�ͳ�ǰ����褦���ѹ��Ǥ���ΤǤ���С������ܤϤ����� �ɤ�����ޤ��󤬥ץ����������ΤˤǤ��ޤ��� �ʲ�����ϰ����Ȥ�������Υ�ե���󥹤���ļ�ꡢ������������Ǥο��ˤ�ä� ����Ť���줿��Ĥ�������֤��ؿ��Ǥ�: ($aref, $bref) = func(\@c, \@d); print "@$aref has more than @$bref\n"; sub func { my ($cref, $dref) = @_; if (@$cref > @$dref) { return ($cref, $dref); } else { return ($dref, $cref); } } =begin original It turns out that you can actually do this also: =end original ����ϰʲ��Τ褦�˽񤯤��Ȥ�Ǥ��ޤ�: (*a, *b) = func(\@c, \@d); print "@a has more than @b\n"; sub func { local (*c, *d) = @_; if (@c > @d) { return (\@c, \@d); } else { return (\@d, \@c); } } =begin original Here we're using the typeglobs to do symbol table aliasing. It's a tad subtle, though, and also won't work if you're using C variables, because only globals (even in disguise as Cs) are in the symbol table. =end original ������Ǥϡ�����ܥ�ơ��֥����̾�Ť��򤹤뤿��˷������֤�ȤäƤ��ޤ��� ���������������̯�ʤ�ΤǤ��ꡢC �ѿ���Ȥä����ˤϤ��ޤ������ޤ���; �ʤ��ʤ顢�������Х�ʤ��(C �ǵ���������Τ�ޤ�)������ ����ܥ�ơ��֥�ˤ��뤫��Ǥ��� =begin original If you're passing around filehandles, you could usually just use the bare typeglob, like C<*STDOUT>, but typeglobs references work, too. For example: =end original �ե�����ϥ�ɥ�򰷤����Ȥ����ΤǤ���С��̾�� C<*STDOUT> �Τ褦�� ��η�������(bare typeglob)��Ȥ����Ȥ��Ǥ��ޤ������������֤� ��ե���󥹤�ư��ޤ��� �㤨��: splutter(\*STDOUT); sub splutter { my $fh = shift; print $fh "her um well a hmmm\n"; } $rec = get_rec(\*STDIN); sub get_rec { my $fh = shift; return scalar <$fh>; } =begin original If you're planning on generating new filehandles, you could do this. Notice to pass back just the bare *FH, not its reference. =end original �������ե�����ϥ�ɥ���������뤳�Ȥ�ͤ��Ƥ���ΤǤ���С� �ʲ��Τ褦�ˤǤ��ޤ��� ��ե���󥹤ǤϤʤ������� *FH ���Ϥ����Ȥ����դ��Ƥ��������� sub openit { my $path = shift; local *FH; return open (FH, $path) ? *FH : undef; } =head2 Prototypes X X (�ץ��ȥ�����) =begin original Perl supports a very limited kind of compile-time argument checking using function prototyping. If you declare =end original Perl �ϤȤƤ�¤�줿���Υ���ѥ�������������å����б����Ƥ��ޤ��� �ʲ��Τ褦����������: sub mypush (+@) =begin original then C takes arguments exactly like C does. The function declaration must be visible at compile time. The prototype affects only interpretation of new-style calls to the function, where new-style is defined as not using the C<&> character. In other words, if you call it like a built-in function, then it behaves like a built-in function. If you call it like an old-fashioned subroutine, then it behaves like an old-fashioned subroutine. It naturally falls out from this rule that prototypes have no influence on subroutine references like C<\&foo> or on indirect subroutine calls like C<&{$subref}> or C<< $subref->() >>. =end original C �� C �����ΤȤޤä���Ʊ����������ޤ��� �ؿ�����ϥ���ѥ�����˲Ļ�Ǥʤ���Фʤ�ޤ��� �ץ��ȥ����פθ��̤ϡ��ؿ��� C<&> ��Ȥ�ʤ������������θƤӽФ��� ��ᤷ���Ȥ��ΤߤǤ��� ����������С��Ȥ߹��ߴؿ���Ʊ���褦�˴ؿ���ƤӽФ��С� ������Ȥ߹��ߴؿ���Ʊ���褦�˿����񤦡��Ȥ������ȤǤ��� �Ť������Υ��֥롼�����Ʊ���褦�˸ƤӽФ��С�����ϸŤ������� ���֥롼�����Ʊ���褦�˿����񤤤ޤ��� C<\&foo> �Τ褦�ʥ��֥롼����Υ�ե���󥹤� C<&{$subref}> �Τ褦�� ����Ū�ʥ��֥롼����ƤӽФ���C<< $subref->() >> �˴ؤ��Ƥϥץ��ȥ����פ� �ʤ�αƶ���ڤܤ��ʤ��Τǡ����ε�§���鳰��ޤ��� =begin original Method calls are not influenced by prototypes either, because the function to be called is indeterminate at compile time, since the exact code called depends on inheritance. =end original �᥽�åɸƤӽФ��ϥץ��ȥ����פ�Ԥ�/�Ԥ�ʤ��ˤ��ƶ�������ޤ���; �ʤ��ʤ� ���ΤʸƤӽФ������ɤϡ��Ѿ��˰�¸���Ƥ��뤿��˥���ѥ�����ˤ� �Գ��������Ǥ��� =begin original Because the intent of this feature is primarily to let you define subroutines that work like built-in functions, here are prototypes for some other functions that parse almost exactly like the corresponding built-in. =end original �Ȥ߹��ߴؿ��Τ褦��ư��륵�֥롼����򤢤ʤ������������Τ� ���ε�ǽ�δ���Ū����Ū�ʤΤǡ��������б������Ȥ߹��ߴؿ��Τ褦�� ��ᤵ�����Ĥ��δؿ��ץ��ȥ����פ�󤲤Ƥ����ޤ��礦�� =begin original Declared as Called as =end original ��� �ƤӽФ� sub mylink ($$) mylink $old, $new sub myvec ($$$) myvec $var, $offset, 1 sub myindex ($$;$) myindex &getstring, "substr" sub mysyswrite ($$$;$) mysyswrite $buf, 0, length($buf) - $off, $off sub myreverse (@) myreverse $a, $b, $c sub myjoin ($@) myjoin ":", $a, $b, $c sub mypop (+) mypop @array sub mysplice (+$$@) mysplice @array, 0, 2, @pushme sub mykeys (+) mykeys %{$hashref} sub myopen (*;$) myopen HANDLE, $name sub mypipe (**) mypipe READHANDLE, WRITEHANDLE sub mygrep (&@) mygrep { /foo/ } $a, $b, $c sub myrand (;$) myrand 42 sub mytime () mytime =begin original Any backslashed prototype character represents an actual argument that must start with that character (optionally preceded by C, C or C), with the exception of C<$>, which will accept any scalar lvalue expression, such as C<$foo = 7> or C<< my_function()->[0] >>. The value passed as part of C<@_> will be a reference to the actual argument given in the subroutine call, obtained by applying C<\> to that argument. =end original �Хå�����å��夬�դ���줿�ץ��ȥ�����ʸ���ϡ��°����� ����ʸ���ǻϤޤ��ΤǤʤ���Фʤ�ʤ����Ȥ�ɽ���ޤ� (���ץ����Ȥ��� C, C, C �����֤���ޤ�); C<$foo = 7> �� C<< my_function()->[0] >> �Τ褦�˥ޡ����ʤ��Ǥ�Ǥ�դ� ������ɽ��������դ��� C<$> ���㳰�Ǥ��� C<@_> �ΰ����Ȥ����Ϥ��줿�����ϡ����Υ��֥롼����ƤӽФ��ˤ����� Ϳ����줿�°����� C<\> ��Ŭ�Ѥ�����ե���󥹤Ȥʤ�ޤ��� =begin original You can use the C<\[]> backslash group notation to specify more than one allowed argument type. For example: =end original C<\[]> �Хå�����å��嵭ˡ�򡢰�Ĥޤ���ʣ���ΰ���������ꤹ�뤿��� �Ȥ��ޤ��� �㤨��: sub myref (\[$@%&*]) =begin original will allow calling myref() as =end original �Ȥ����Τϰʲ��Τ褦�� myref() ��ƤӽФ��Τ����: myref $var myref @array myref %hash myref &sub myref *glob =begin original and the first argument of myref() will be a reference to a scalar, an array, a hash, a code, or a glob. =end original myref() �κǽ�ΰ����� �����顢���󡢥ϥå��塢�����ɡ������֤Τ����줫�ؤ� ��ե���󥹤Ǥ��� =begin original Unbackslashed prototype characters have special meanings. Any unbackslashed C<@> or C<%> eats all remaining arguments, and forces list context. An argument represented by C<$> forces scalar context. An C<&> requires an anonymous subroutine, which, if passed as the first argument, does not require the C keyword or a subsequent comma. =end original �Хå�����å��夬�դ����Ƥ��ʤ�ʸ�������̤ʰ�̣����äƤ��ޤ��� �Хå�����å�����դ����Ƥ��ʤ� ���٤Ƥ� C<@> ��C<%> �ϻĤ�ΰ������Ƥ� ��äƤ��ޤ�������˥ꥹ�ȥ���ƥ����Ȥ������ޤ��� C<$> ��ɽ���������ϥ����饳��ƥ����Ȥ�������ޤ��� �������Ȥ����Ϥ��줿��硢C<&> �� C ������ɤ�Ϣ³��������ޤ� �׵ᤷ�ʤ��褦��̵̾���֥롼������׵ᤷ�ޤ��� =begin original A C<*> allows the subroutine to accept a bareword, constant, scalar expression, typeglob, or a reference to a typeglob in that slot. The value will be available to the subroutine either as a simple scalar, or (in the latter two cases) as a reference to the typeglob. If you wish to always convert such arguments to a typeglob reference, use Symbol::qualify_to_ref() as follows: =end original C<*> �ϡ������åȤˤ������ñ�졢����������鼰���������֡� �������֤��Ф����ե���󥹤�����Ƥ��ޤ��� �����ͤϥ��֥롼����ˤȤä�ñ��ʥ�����Ȥ��뤳�Ȥ� �������֤��Ф����ե���󥹤ˤ�ʤ�ޤ��� ���Τ褦�ʰ������˷������֥�ե���󥹤��Ѵ����������ϡ� Symbol::qualify_to_ref() ��ʲ��Τ褦�˻Ȥ��ޤ�: use Symbol 'qualify_to_ref'; sub foo (*) { my $fh = qualify_to_ref(shift, caller); ... } =begin original The C<+> prototype is a special alternative to C<$> that will act like C<\[@%]> when given a literal array or hash variable, but will otherwise force scalar context on the argument. This is useful for functions which should accept either a literal array or an array reference as the argument: =end original C<+> �ץ��ȥ����פ� C<$> ���ü������ʪ�ǡ���ƥ��������ϥå����ѿ��� Ϳ������� C<\[@%]> �Τ褦��ư��ޤ���������ʤ���а����� �����饳��ƥ����Ȥ������ޤ��� ����ϰ����Ȥ��ƥ�ƥ�������ޤ��������ե���󥹤Τɤ��餫�� �����դ���褦�ʴؿ���ͭ�ѤǤ�: sub mypush (+@) { my $aref = shift; die "Not an array or arrayref" unless ref $aref eq 'ARRAY'; push @$aref, @_; } =begin original When using the C<+> prototype, your function must check that the argument is of an acceptable type. =end original �ؿ��� C<+> �ץ��ȥ����פ�Ȥä��Ȥ��������������դ����뷿���� �����å����ʤ���Фʤ�ޤ��� =begin original A semicolon (C<;>) separates mandatory arguments from optional arguments. It is redundant before C<@> or C<%>, which gobble up everything else. =end original ���ߥ����� (C<;>) �ϡ�ɬ�ܤΰ����Ⱦ�ά��ǽ�ʰ����Ȥ�ʬ�䤷�ޤ��� C<@> �� C<%> �����ǤϤ���Ͼ�Ĺ�Ǥ�; ����¾�Τ�Τ�ۼ����ޤ��� =begin original As the last character of a prototype, or just before a semicolon, a C<@> or a C<%>, you can use C<_> in place of C<$>: if this argument is not provided, C<$_> will be used instead. =end original �ץ��ȥ����פκǸ��ʸ�������뤤�ϥ��ߥ�����C<@>��C<%> ��ľ���ˡ�C<$> �� ����� C<_> ��Ȥ��ޤ�: ������Ϳ�����ʤ���硢C<$_> ������� �Ȥ��ޤ��� =begin original Note how the last three examples in the table above are treated specially by the parser. C is parsed as a true list operator, C is parsed as a true unary operator with unary precedence the same as C, and C is truly without arguments, just like C. That is, if you say =end original �����κǸ�λ��ĤΤ�Τϡ���ʸ���ϴ郎���̰�������Ȥ������Ȥ� ���դ��Ƥ��������� C �������Υꥹ�ȱ黻�ҤȤ��Ʋ��Ϥ��졢C �� C �� Ʊ����ñ��黻�Ҥ�ͥ���̤���ä�����ñ��黻�ҤȤ��ơ� ������ C �� C ��Ʊ���ͤʰ�������ʤ���ΤȤ��� ���Ϥ���ޤ����Ĥޤꡢ mytime +2; =begin original you'll get C, not C, which is how it would be parsed without a prototype. If you want to force a unary function to have the same precedence as a list operator, add C<;> to the end of the prototype: =end original �Ȥ���ȡ��ץ��ȥ����פʤ��ξ��˥ѡ�������� C �ǤϤʤ��� C �Ȥʤ�ޤ��� ñ��ؿ����ꥹ�ȱ黻�Ҥ�Ʊ��ͥ���̤���Ĥ褦�ˤ��������ʤ顢�ץ��ȥ����פ� ������ C<;> ���ɲä��Ƥ�������: sub mygetprotobynumber($;); mygetprotobynumber $a > $b; # parsed as mygetprotobynumber($a > $b) =begin original The interesting thing about C<&> is that you can generate new syntax with it, provided it's in the initial position: X<&> =end original C<&> �˴ؤ��ƶ�̣�������Ȥϡ�������֤�Ȥäƿ�������ʸ�� �����Ǥ���Ȥ������ȤǤ�: X<&> sub try (&@) { my($try,$catch) = @_; eval { &$try }; if ($@) { local $_ = $@; &$catch; } } sub catch (&) { $_[0] } try { die "phooey"; } catch { /phooey/ and print "unphooey\n"; }; =begin original That prints C<"unphooey">. (Yes, there are still unresolved issues having to do with visibility of C<@_>. I'm ignoring that question for the moment. (But note that if we make C<@_> lexically scoped, those anonymous subroutines can act like closures... (Gee, is this sounding a little Lispish? (Never mind.)))) =end original ����� C<��unphooey��> ����Ϥ��ޤ��� (������C<@_> �βĻ����˴ؤ��Ʋ�褷�Ƥ��ʤ����Ȥ�����ޤ��� �������ǤϤ����̵�뤷�ޤ��� (��������C<@_> ��쥭�����륹�����פˤ���о嵭�Υ��֥롼����ϥ��������㡼�� �褦�˿����񤦤��Ȥ��Ǥ��ޤ�... (�󡼡�����äƤ��硼�ä� Lisp �äݤ�����? (���ˤ��ʤ��Ǥ͡�)))) =begin original And here's a reimplementation of the Perl C operator: X =end original �ʲ������ Perl �� C �黻�ҤΤκƼ����Ǥ�: X sub mygrep (&@) { my $code = shift; my @result; foreach $_ (@_) { push(@result, $_) if &$code; } @result; } =begin original Some folks would prefer full alphanumeric prototypes. Alphanumerics have been intentionally left out of prototypes for the express purpose of someday in the future adding named, formal parameters. The current mechanism's main goal is to let module writers provide better diagnostics for module users. Larry feels the notation quite understandable to Perl programmers, and that it will not intrude greatly upon the meat of the module, nor make it harder to read. The line noise is visually encapsulated into a small pill that's easy to swallow. =end original �����οͤϡ������˱ѿ�����Ȥä��ץ��ȥ����פ򹥤फ�⤷��ޤ��� �ѿ����ϡ�����̾���դ����������ɲä���Ȥ��Τ���˰տ�Ū�˻Ȥ鷺�� �Ĥ��Ƥ���ΤǤ��� �������ǤΥץ��ȥ����פε����μ����Ū�ϥ⥸�塼���Ԥ����Υ桼������ �Ф��Ƥ���ɤ����ǥ�å��������󶡤�����褦�ˤ��뤿��Τ�ΤʤΤǤ��� ���ε�ˡ�� Perl �ץ�����ޤ��������򤷤䤹�����⥸�塼�����Ȥ� ��������褦�ʤ��Ȥ��ɤߤŤ餯�����ꤹ�뤳�Ȥ�ʤ��� Larry �Ϲͤ��Ƥ��ޤ��� �����λ����ϰ��߹��ߤ䤹�������ʴ����˻��Ū�˲����������ΤǤ��� =begin original If you try to use an alphanumeric sequence in a prototype you will generate an optional warning - "Illegal character in prototype...". Unfortunately earlier versions of Perl allowed the prototype to be used as long as its prefix was a valid prototype. The warning may be upgraded to a fatal error in a future version of Perl once the majority of offending code is fixed. =end original �⤷�ץ��ȥ����פ˱ѿ�����Ȥ����Ȥ���ȡ����ץ����ηٹ� "Illegal character in prototype..." ����������ޤ��� ��ǰ�ʤ��顢���ΥС������� Perl �Ǥϡ�ͭ���ʥץ��ȥ����פ����֤���Ƥ��� ����С��ѿ�����ޤ�ץ��ȥ����פ�ǧ����Ƥ��ޤ����� ���ηٹ�ϡ��ܾ��ʥ����ɤ�����ʬ���������줿�ʤ顢����ΥС������� Perl ����̿Ū���顼�˳ʾ夲����뤫�⤷��ޤ��� =begin original It's probably best to prototype new functions, not retrofit prototyping into older ones. That's because you must be especially careful about silent impositions of differing list versus scalar contexts. For example, if you decide that a function should take just one parameter, like this: =end original �������ؿ��˥ץ��ȥ����פ��դ���Τ������餯�����Ǥ��ꡢ�Ť��ؿ����Ф��� �ץ��ȥ����פ��դ��뤳�ȤϤ褯����ޤ��� �ʤ��ʤ顢(�ץ��ȥ����פ��դ������Ȥˤ�ä�)�ꥹ�ȥ���ƥ����Ȥ� �����饳��ƥ����Ȥ��ۤä��Ѥ��Ƥ��ޤ��褦�ʤ��Ȥ˴ؤ��� �ä����դ��ʤ���Фʤ�ʤ�����Ǥ��� ���Ȥ��аʲ�����Τ褦�ʤ�����Ĥΰ�������ȷ�᤿�ؿ���ͤ��Ƥߤޤ��礦: sub func ($) { my $n = shift; print "you gave me $n\n"; } =begin original and someone has been calling it with an array or expression returning a list: =end original �����ơ�ï�������δؿ���ꥹ�Ȥ��֤��褦������估������Ȥ��� �Ϥ����Ȥ����: func(@foo); func( split /:/ ); =begin original Then you've just supplied an automatic C in front of their argument, which can be more than a bit surprising. The old C<@foo> which used to hold one thing doesn't get passed in. Instead, C now gets passed in a C<1>; that is, the number of elements in C<@foo>. And the C gets called in scalar context so it starts scribbling on your C<@_> parameter list. Ouch! =end original ��ưŪ�� C ������������(���ä����)�դ����ޤ�; ����ˤ� ���������Ӥä��ꤹ�뤳�Ȥˤʤ뤫�⤷��ޤ��� ����ޤǤ����Ǥ��ä��褦�ʡ����Ǥ���ä� C<@foo> ���Ϥ���뤳�ȤϤ���ޤ��� �������ꡢC �� C<1>���Ĥޤ� C<@foo> �����Ǥο�������褦�ˤʤ�ޤ��� ������ C �ϥ����饳��ƥ����ȤǸƤӽФ��졢�ѥ�᡼���ꥹ�� C<@_> ����񤭤�Ϥ�Ƥ��ޤ��ޤ��� ���������� =begin original This is all very powerful, of course, and should be used only in moderation to make the world a better place. =end original ������󤳤�Ͻ�ʬ���Ϥʤ�ΤǤ��ꡢ���������ɤ����ˤ���Ȥ�����Ū�� �¤äƻ��Ѥ��٤���ΤǤ��礦�� =head2 Constant Functions X (����ؿ�) =begin original Functions with a prototype of C<()> are potential candidates for inlining. If the result after optimization and constant folding is either a constant or a lexically-scoped scalar which has no other references, then it will be used in place of function calls made without C<&>. Calls made using C<&> are never inlined. (See F for an easy way to declare most constants.) =end original C<()> �Ȥ����ץ��ȥ����פ���ä��ؿ��ϥ���饤��Ÿ��������ǽ���� ���äƤ��ޤ��� ��Ŭ����������߹��߸�η�̤���Ĥ�����������Υ�ե���󥹤�����ʤ� �쥭�����륹�����פΥ�����Ǥ��ä��ʤ�С����δؿ��� C<&> ��Ȥ鷺�� �ƤӤ��줿�Ȥ��˸ƤӽФ��Τ��ξ���֤���ޤ��� C<&> ��ȤäƸƤӽФ��줿�ؿ��Ϸ褷�ƥ���饤��Ÿ������뤳�Ȥ� ����ޤ��� (�ۤȤ�ɤ������������뤿��δ�ñ����ˡ�ϡ�F �� ���Ȥ��Ƥ���������) =begin original The following functions would all be inlined: =end original �ʲ��˵󤲤��ؿ������ƥ���饤��Ÿ�������Ǥ��礦: =begin original sub pi () { 3.14159 } # Not exact, but close. sub PI () { 4 * atan2 1, 1 } # As good as it gets, # and it's inlined, too! sub ST_DEV () { 0 } sub ST_INO () { 1 } =end original sub pi () { 3.14159 } # ���ΤǤϤʤ����ᤤ�� sub PI () { 4 * atan2 1, 1 } # ��ǽ�ʸ¤��ɤ���� # �����Ƥ����Ÿ������ޤ�! sub ST_DEV () { 0 } sub ST_INO () { 1 } sub FLAG_FOO () { 1 << 8 } sub FLAG_BAR () { 1 << 9 } sub FLAG_MASK () { FLAG_FOO | FLAG_BAR } sub OPT_BAZ () { not (0x1B58 & FLAG_MASK) } sub N () { int(OPT_BAZ) / 3 } sub FOO_SET () { 1 if FLAG_MASK & FLAG_FOO } =begin original Be aware that these will not be inlined; as they contain inner scopes, the constant folding doesn't reduce them to a single constant: =end original �ʲ��Τ�Τϥ���饤��Ÿ������ʤ����Ȥ����դ��Ƥ�������; �����¦�˥������פ�����Τǡ����߹��ޤ줿�������Ĥ�����˺︺�Ǥ��ޤ���: sub foo_set () { if (FLAG_MASK & FLAG_FOO) { 1 } } sub baz_val () { if (OPT_BAZ) { return 23; } else { return 42; } } =begin original If you redefine a subroutine that was eligible for inlining, you'll get a warning by default. (You can use this warning to tell whether or not a particular subroutine is considered constant.) The warning is considered severe enough not to be affected by the B<-w> switch (or its absence) because previously compiled invocations of the function will still be using the old value of the function. If you need to be able to redefine the subroutine, you need to ensure that it isn't inlined, either by dropping the C<()> prototype (which changes calling semantics, so beware) or by thwarting the inlining mechanism in some other way, such as =end original ����饤��Ÿ������Τ�Ŭ�ڤǤ��ä����֥롼�������������ȥǥե���ȤǤ� �ٹ������뤳�Ȥˤʤ�ޤ��� (���ηٹ�򡢤��륵�֥롼����������֥롼����Ȥ���ǧ������뤫�ɤ����� ���̤��뤿��˻Ȥ����Ȥ��Ǥ��ޤ���) �����˥���ѥ��뤷���ؿ��ε�ư�ˤ�äƤ��δؿ��θŤ��ͤ�Ȥ�³����Τǡ� ���ηٹ�� B<-w> ���ץ����(�ޤ��Ϥ��줬�ʤ�����)�˱ƶ���������Τ� ����ˤϽ��礹����ȹͤ����ޤ����� ���Υ��֥롼����������Ǥ���ɬ�פ�����Τʤ�С�C<()> �ץ��ȥ����פ� ����(����ϸƤӽФ��Υ��ޥ�ƥ��������Ѥ��Ƥ��ޤ��Τ����դ��Ƥ�������)���� �ʲ�����Τ褦�ˤ��ƥ���饤��Ÿ�������� Ư�����ʤ��褦�ˤ��ƥ��֥롼���󤬥���饤��Ÿ������Ƥ��ʤ����Ȥ� �ݾڤ���ɬ�פ�����ޤ��� sub not_inlined () { 23 if $]; } =head2 Overriding Built-in Functions X X X X (�Ȥ߹��ߴؿ��Υ����С��饤��) =begin original Many built-in functions may be overridden, though this should be tried only occasionally and for good reason. Typically this might be done by a package attempting to emulate missing built-in functionality on a non-Unix system. =end original ¿�����Ȥ߹��ߴؿ��ϥ����С��饤�ɤ��뤳�Ȥ��Ǥ��ޤ�; �������������Ԥ��Τϡ� ����������ͳ�Ⱦ����Ȥ�����Ȥ��Τߤ˸¤�٤��Ǥ��礦�� ���줬�Ԥ���ŵ��Ū����ϡ��� UNIX �����ƥ�ˤ����Ʒ礱�Ƥ����Ȥ߹��ߵ�ǽ�� ���ߥ�졼�Ȥ��뤿��˥ѥå�������Ȥ����Ȥ�����Ǥ��礦�� =begin original Overriding may be done only by importing the name from a module at compile time--ordinary predeclaration isn't good enough. However, the C pragma lets you, in effect, predeclare subs via the import syntax, and these names may then override built-in ones: =end original �����С��饤�ɤϥ���ѥ�����˥⥸�塼�뤫��Τ�̾���� import �Ǥ��ޤ�-- �̾���������ǤϽ�ʬ�ǤϤ���ޤ��� �������ʤ��顢C �ץ饰�ޤ� import ��ʸ���̤�����������Ԥ��� ����ˤ�����̾�����Ȥ߹��ߤΤ�Τ򥪡��С��饤�ɤǤ���褦�ˤ��ޤ�: use subs 'chdir', 'chroot', 'chmod', 'chown'; chdir $somewhere; sub chdir { ... } =begin original To unambiguously refer to the built-in form, precede the built-in name with the special package qualifier C. For example, saying C always refers to the built-in C, even if the current package has imported some other subroutine called C<&open()> from elsewhere. Even though it looks like a regular function call, it isn't: the CORE:: prefix in that case is part of Perl's syntax, and works for any keyword, regardless of what is in the CORE package. Taking a reference to it, that is, C<\&CORE::open>, only works for some keywords. See L. =end original ۣ�椵�ʤ��Ȥ߹��ߤΤ�Τ򻲾Ȥ��뤿��ˡ����̤ʥѥå����������� C ���Ȥ߹��ߤ�̾�������֤��뤳�Ȥ��Ǥ��ޤ��� ���Ȥ��� C �Ȥ���ȡ����Ȥ������ȥѥå������� C<&open()> �Ȥ��ä��̤Υ��֥롼����� import ���Ƥ����Ȥ��Ƥ� ����Ͼ���Ȥ߹��ߴؿ��� C �򻲾Ȥ��ޤ��� ������̾�δؿ��ƤӽФ��Τ褦�˸����ޤ����������ǤϤ���ޤ���: ���ξ��� CORE:: ��Ƭ���� Perl ��ʸˡ�ΰ����ǡ�CORE �ѥå������˲������뤫�� �ؤ�餺���ɤΤ褦�ʥ�����ɤǤ�ư��ޤ��� C<\&CORE::open> �Τ褦�ˡ�������Ф����ե���󥹤μ����ϡ������� ������ɤǤΤ�ư��ޤ��� L �򻲾Ȥ��Ƥ��������� =begin original Library modules should not in general export built-in names like C or C as part of their default C<@EXPORT> list, because these may sneak into someone else's namespace and change the semantics unexpectedly. Instead, if the module adds that name to C<@EXPORT_OK>, then it's possible for a user to import the name explicitly, but not implicitly. That is, they could say =end original �饤�֥��⥸�塼��ϡ�C ���Ȥ� C �Τ褦���Ȥ߹��ߤ�̾���� �ǥե���Ȥ� C<@EXPORT> �ꥹ�Ȥΰ����Ȥ���export ���٤��ǤϤ���ޤ���; �ʤ��ʤ顢�饤�֥���Ȥä��ͤ�̾�����֤������ͽ�����ʤ�ư��� �Ƥӵ�������ǽ�������뤫��Ǥ��� C<@EXPORT_OK> ��̾�����ɲä���С��桼����������̾�����ۤ˻��ꤹ��� import ���뤳�Ȥ��Ǥ������ۤ���� import ����Ƥ��ޤ����ȤϤ���ޤ��� �Ĥޤꡢ�ʲ��Τ褦�ˤ���� use Module 'open'; =begin original and it would import the C override. But if they said =end original C �Υ����С��饤�ɤ򥤥�ݡ��Ȥ��ޤ��� ���������ʲ��Τ褦�ˤ���� use Module; =begin original they would get the default imports without overrides. =end original �ǥե���ȤΥ���ݡ��Ȥ�Ԥ��������С��饤�ɤϤ��ޤ��� =begin original The foregoing mechanism for overriding built-in is restricted, quite deliberately, to the package that requests the import. There is a second method that is sometimes applicable when you wish to override a built-in everywhere, without regard to namespace boundaries. This is achieved by importing a sub into the special namespace C. Here is an example that quite brazenly replaces the C operator with something that understands regular expressions. =end original �Ȥ߹��ߤΤ�Τ��Ф��륪���С��饤�ǥ��󥰤Τ���ε����� ����ݡ��Ȥ��׵ᤷ���ѥå����������¤���Ƥ��ޤ��� ̾�����֤˴ط��ʤ��Ȥ߹��ߤ�Ǥ�դΤ�Τ򥪡��С��饤�ɤ������� �ͤ����Ȥ��˻Ȥ��뤳�Ȥ⤢�������ܤ���ˡ������ޤ��� ������ü��̾������ C ���Ф��� sub �� ����ݡ��Ȥ��뤳�Ȥˤ���ΤǤ��� �ʲ��ˤ���äȤ�������ɽ����Ȥä� C �黻�Ҥ��֤����������󤲤ޤ��� package REGlob; require Exporter; @ISA = 'Exporter'; @EXPORT_OK = 'glob'; sub import { my $pkg = shift; return unless @_; my $sym = shift; my $where = ($sym =~ s/^GLOBAL_// ? 'CORE::GLOBAL' : caller(0)); $pkg->export($where, $sym, @_); } sub glob { my $pat = shift; my @got; if (opendir my $d, '.') { @got = grep /$pat/, readdir $d; closedir $d; } return @got; } 1; =begin original And here's how it could be (ab)used: =end original �����ưʲ��ϰ����Ȥ���(���⤷��ʤ�)��Ǥ�: #use REGlob 'GLOBAL_glob'; # override glob() in ALL namespaces package Foo; use REGlob 'glob'; # override glob() in Foo:: only print for <^[a-z_]+\.pm\$>; # show all pragmatic modules =begin original The initial comment shows a contrived, even dangerous example. By overriding C globally, you would be forcing the new (and subversive) behavior for the C operator for I namespace, without the complete cognizance or cooperation of the modules that own those namespaces. Naturally, this should be done with extreme caution--if it must be done at all. =end original �ǽ�Υ�������ʬ���Լ����ǡ������Ǥ��餢����Ǥ��� �������Х�� C �򥪡��С��饤�ɤ��뤳�Ȥˤ�äơ� ������ǧ������Ƥ��ʤ��ä���⥸�塼���ͭ��̾�����֤Ȥζ�Ĵ�� ��θ�����ˡ�C ��ư� I<���Ƥ�> ̾�����֤Ƕ���Ū�˿�����(�������˲�Ū��)��Τˤʤ�ޤ��� �������ä����Ȥ�(���줬�����ˤ��ʤ���Ф����ʤ����ȤȤ������) �礤�����դ��������ǹԤ��٤���ΤǤ��� =begin original The C example above does not implement all the support needed to cleanly override perl's C operator. The built-in C has different behaviors depending on whether it appears in a scalar or list context, but our C doesn't. Indeed, many perl built-in have such context sensitive behaviors, and these must be adequately supported by a properly written override. For a fully functional example of overriding C, study the implementation of C in the standard library. =end original ���Ҥ� C ����ϡ�perl �� C �黻�Ҥ򥪡��С��饤�ɤ���Τ� ɬ�פ����ƤΤ��Ȥ�������ƤϤ��ޤ��� �Ȥ߹��ߤ� C �Ϥ��줬�����饳��ƥ����ȤǻȤ�줿�Τ� �ꥹ�ȥ���ƥ����ȤǻȤ�줿�Τ��ˤ�äưۤʤ�ư��򤷤ޤ����� ��������� C �ǤϤ����ʤäƤ��ޤ��� perl ���Ȥ߹��ߤΤ�Τ�¿�������Τ褦�˥���ƥ����Ȥˤ�äư㤦ư��򤷡� �����С��饤�ɤ����Τ򵭽Ҥ�����ˤϤ�����Ȥ���� ���ݡ��Ȥ��Ƥ��ʤ���Фʤ�ޤ��� C �Υ����С��饤�ǥ��󥰤δ����Ǥϡ� ɸ��饤�֥��ˤ��� C �μ������ٶ����Ƥ��������� =begin original When you override a built-in, your replacement should be consistent (if possible) with the built-in native syntax. You can achieve this by using a suitable prototype. To get the prototype of an overridable built-in, use the C function with an argument of C<"CORE::builtin_name"> (see L). =end original �Ȥ߹��ߴؿ��򥪡��С��饤�ɤ���Ȥ��������С��饤�ɤ����ؿ��� �Ȥ߹��ߴؿ��θ���ʸˡ(�⤷�����)�Ȱ�Ӥ��Ƥ���٤��Ǥ��� �����Ŭ�ڤʥץ��ȥ����פ�Ȥ����Ȥ�ã���Ǥ��ޤ��� �����С��饤�ɤǤ����Ȥ߹��ߴؿ��Υץ��ȥ����פ����뤿��ˤϡ� C<"CORE::builtin_name"> ��������Ȥ��� C �ؿ���ȤäƤ������� (L �򻲾Ȥ��Ƥ�������)�� =begin original Note however that some built-ins can't have their syntax expressed by a prototype (such as C or C). If you override them you won't be able to fully mimic their original syntax. =end original (C �� C �Τ褦��)ʸˡ��ץ��ȥ����פ�ɽ���Ǥ��ʤ� �Ȥ߹��ߴؿ������դ��Ƥ��������� �⤷�����򥪡��С��饤�ɤ���ȡ���Ȥ�ʸˡ�����˿����뤳�Ȥ� �Ǥ��ޤ��� =begin original The built-ins C, C and C can also be overridden, but due to special magic, their original syntax is preserved, and you don't have to define a prototype for their replacements. (You can't override the C syntax, though). =end original �Ȥ߹��ߤ� C, C, C �⥪���С��饤�ɤǤ��ޤ��������̤� ��ˡ�ˤ�äơ������θ���ʸˡ����¸���졢�����С��饤�ɤ�����ΤΤ���� �ץ��ȥ����פ��������ɬ�פϤ���ޤ��� (��������C ʸˡ�ϥ����С��饤�ɤǤ��ޤ���)�� =begin original C has special additional dark magic: if you invoke your C replacement as C, it will actually receive the argument C<"Foo/Bar.pm"> in @_. See L. =end original C �����̤��ɲäι���ˡ������ޤ�: C �򥪡��С��饤�ɤ��� ��Τ� C �Ȥ��Ƶ�ư����ȡ��ºݤˤ� @_ �˰������Ȥ��� C<"Foo/Bar.pm"> ��������ޤ��� L �򻲾Ȥ��Ƥ��������� =begin original And, as you'll have noticed from the previous example, if you override C, the C<< <*> >> glob operator is overridden as well. =end original �����ơ��������㤫�鵤�դ������⤷��ޤ��󤬡��⤷ C �� �����С��饤�ɤ���ȡ������ֱ黻�� C<< <*> >> �⥪���С��饤�ɤ���ޤ��� =begin original In a similar fashion, overriding the C function also overrides the equivalent I/O operator C<< >>. Also, overriding C also overrides the operators C<``> and C. =end original Ʊ�ͤˡ�C �ؿ��򥪡��С��饤�ɤ���� ������ I/O �黻�ҤǤ��� C<< >> �⥪���С��饤�ɤ��ޤ��� �ޤ���C �򥪡��С��饤�ɤ���ȡ��黻�� C<``> �� C �� �����С��饤�ɤ��ޤ��� =begin original Finally, some built-ins (e.g. C or C) can't be overridden. =end original �Ǹ�ˡ������Ĥ����Ȥ߹��ߴؿ�(C �� C) �� �����С��饤�ɤǤ��ޤ��� =head2 Autoloading X X (�����ȥ�����) =begin original If you call a subroutine that is undefined, you would ordinarily get an immediate, fatal error complaining that the subroutine doesn't exist. (Likewise for subroutines being used as methods, when the method doesn't exist in any base class of the class's package.) However, if an C subroutine is defined in the package or packages used to locate the original subroutine, then that C subroutine is called with the arguments that would have been passed to the original subroutine. The fully qualified name of the original subroutine magically appears in the global $AUTOLOAD variable of the same package as the C routine. The name is not passed as an ordinary argument because, er, well, just because, that's why. (As an exception, a method call to a nonexistent C or C method is just skipped instead. Also, if the AUTOLOAD subroutine is an XSUB, there are other ways to retrieve the subroutine name. See L for details.) =end original �������Ƥ��ʤ����֥롼�����ƤӽФ�����硢�̾�Ϥ���ʥ��֥롼����� �ʤ��Ȥ��ä����ƤΥ��顼��¨�¤�ȯ������Ǥ��礦(�᥽�åɤȤ��� �Ȥ��Ƥ��륵�֥롼�����Ʊ�ͤˡ��᥽�åɤ����Υ��饹�Υѥå������� ���٤Ƥδ��쥯�饹���¸�ߤ��Ƥ��ʤ��ä��Ȥ�)�� ��������C ���֥롼���󤬤��Υѥå�����������������Ƥ��뤫 ���Υ��֥롼����ǻȤ���ѥå�����������������Ƥ���С� ���Υ��֥롼������Ф����Ϥ��줿�Ǥ�����������ȼ�äƤ��� C ���֥롼���󤬸ƤӽФ���ޤ��� ���Υ��֥롼����δ����������줿̾���� C �롼�����Ʊ�� �ѥå������Υ������Х���ѿ� $AUTOLOAD ����˸���ޤ��� ����̾�����̾�ΰ����Ȥ����Ϥ���뤳�ȤϤ���ޤ��� �ʤ��ʤ顢���Ρ��������ʤ�Ȥ��������줬��ͳ�Ǥ��� (�㳰�Ȥ��ơ�¸�ߤ��ʤ� C �� C �᥽�åɤؤθƤӽФ��� ñ��̵�뤵��ޤ��� �ޤ���AUTOLOAD ���֥롼���� XSUB �ʤ顢���֥롼����̾��������뤿��� ����¾����ˡ������ޤ��� �ܤ����� L �򻲾Ȥ��Ƥ���������) =begin original Many C routines load in a definition for the requested subroutine using eval(), then execute that subroutine using a special form of goto() that erases the stack frame of the C routine without a trace. (See the source to the standard module documented in L, for example.) But an C routine can also just emulate the routine and never define it. For example, let's pretend that a function that wasn't defined should just invoke C with those arguments. All you'd do is: =end original ¿���� C �롼����� eval() ��Ȥä��׵᥵�֥롼����� �Ф�������ǥ����ɤ��졢C �롼����Υ����å��ե졼��� �ȥ졼���ʤ��˾ä��Ƥ��ޤ��褦�����̤ʷ����� goto() ��Ȥ����֥롼����� �¹Ԥ��ޤ��� (�����ɸ��� C �⥸�塼��Υ������򻲾Ȥ��Ƥ���������) ��������C �롼����Ϥ��Τ褦�ʥ롼���������򤹤뤳�Ȥ�Ǥ��ơ� ���Ĥ����������ޤ��� ���Ȥ��С��������Ƥʤ��ؿ������ä��Ȥ��ˡ����������Ȥ��� C ��ư����褦�ˤ����ޤ��� ���ʤ���������Ȥ��Ƥ��뤳�ȤϤ����������ȤǤ�: sub AUTOLOAD { my $program = $AUTOLOAD; $program =~ s/.*:://; system($program, @_); } date(); who('am', 'i'); ls('-l'); =begin original In fact, if you predeclare functions you want to call that way, you don't even need parentheses: =end original ���Τ�����ǸƤӽФ������ؿ������������Ƥ����С���̤��� ɬ�פǤϤʤ��ʤ�ޤ��� use subs qw(date who ls); date; who "am", "i"; ls '-l'; =begin original A more complete example of this is the Shell module on CPAN, which can treat undefined subroutine calls as calls to external programs. =end original ������Τ�äȴ����ʤ�Τ���CPAN �ˤ��� Shell �⥸�塼��Ǥ�; ����� ̤����Υ��֥롼����θƤӽФ������ץ������θƤӽФ��Ȥ��ư����ޤ��� =begin original Mechanisms are available to help modules writers split their modules into autoloadable files. See the standard AutoLoader module described in L and in L, the standard SelfLoader modules in L, and the document on adding C functions to Perl code in L. =end original ���λųݤ��ϡ��⥸�塼���Ԥ��⥸�塼���ư�����ɲ�ǽ�ʥե������ ʬ�䤹��Τ�����뤿��˻��Ѳ�ǽ�Ǥ��� L �� L ����������Ƥ��� ɸ��� AutoLoader �⥸�塼��ȡ�L ����������Ƥ��� ɸ��� SelfLoader �⥸�塼�롢������ L �ˤ��� Perl �ץ������� C �δؿ����ɲä��뤳�Ȥ˴ؤ���ɥ�����Ȥ򻲾Ȥ��Ƥ��������� =head2 Subroutine Attributes X X X (���֥롼����°��) =begin original A subroutine declaration or definition may have a list of attributes associated with it. If such an attribute list is present, it is broken up at space or colon boundaries and treated as though a C had been seen. See L for details about what attributes are currently supported. Unlike the limitation with the obsolescent C, the C syntax works to associate the attributes with a pre-declaration, and not just with a subroutine definition. =end original ���֥롼�������������ˤϡ�����ȷ���դ���줿°���Υꥹ�Ȥ� �������뤳�Ȥ�����ޤ��� ���Τ褦��°������ä���硢���ڡ��������������ڤ�Ȥ���ʬ�䤵�졢 C �����ä����Τ褦�˰����ޤ��� °���������б����Ƥ���ܺ٤ˤĤ��Ƥ� L �򻲾Ȥ��Ƥ��������� �Ť� C �����¤Ȱ�äơ�C ��ʸˡ�� ��������Ǥ�ư������֥롼������������ǤϤ���ޤ��� =begin original The attributes must be valid as simple identifier names (without any punctuation other than the '_' character). They may have a parameter list appended, which is only checked for whether its parentheses ('(',')') nest properly. =end original °����ñ��ʼ��̻�̾('_' �ʳ��ζ������ʤ�)�Ǥʤ���Фʤ�ޤ��� �ѥ�᡼���ꥹ�Ȥ��ɲä���Ȥ��ˡ����('(',')')�Υͥ��Ȥ� ���������ɤ�������������å����ޤ��� =begin original Examples of valid syntax (even though the attributes are unknown): =end original (°�����������Ȥ��Ƥ�)�����ʸˡ����Ǥ�: sub fnord (&\%) : switch(10,foo(7,3)) : expensive; sub plugh () : Ugly('\(") :Bad; sub xyzzy : _5x5 { ... } =begin original Examples of invalid syntax: =end original ������ʸˡ����Ǥ�: sub fnord : switch(10,foo(); # ()-string not balanced sub snoid : Ugly('('); # ()-string not balanced sub xyzzy : 5x5; # "5x5" not a valid identifier sub plugh : Y2::north; # "Y2::north" not a simple identifier sub snurt : foo + bar; # "+" not a colon or space =begin original The attribute list is passed as a list of constant strings to the code which associates them with the subroutine. In particular, the second example of valid syntax above currently looks like this in terms of how it's parsed and invoked: =end original °���ꥹ�Ȥϥ��֥롼����ȷ���դ���줿�����ɤ����ʸ����� �ꥹ�ȤȤ����Ϥ���ޤ��� �äˡ��嵭��ͭ����ʸˡ���������Ǥϡ��ɤΤ褦�˥ѡ����ȵ�ư�� �Ԥ��뤫�Ȥ������ˤ����Ƥϰʲ��Τ褦�ˤʤ�ޤ�: use attributes __PACKAGE__, \&plugh, q[Ugly('\(")], 'Bad'; =begin original For further details on attribute lists and their manipulation, see L and L. =end original °���ꥹ�ȤȤ������˴ؤ��뤵��ʤ�ܺ٤ˤĤ��Ƥϡ� L �򻲾Ȥ��Ƥ��������� =head1 SEE ALSO =begin original See L for more about references and closures. See L if you'd like to learn about calling C subroutines from Perl. See L if you'd like to learn about calling Perl subroutines from C. See L to learn about bundling up your functions in separate files. See L to learn what library modules come standard on your system. See L to learn how to make object method calls. =end original ��ե���󥹤ȥ��������㡼�ˤĤ��Ƥ� L �� ���Ȥ��Ƥ��������� Perl ���� C �Υ��֥롼�����ƤӽФ����Ȥ˴ؤ����Τꤿ����С� L�򻲾Ȥ��Ƥ��������� Perl �Υ��֥롼����� C ����ƤӽФ��������� L �򻲾Ȥ��Ƥ��������� ��ʬ�δؿ����̤Υե�����ǹ��ۤ��뤳�Ȥ˴ؤ��Ƥ� L �򻲾Ȥ��Ƥ��������� �ɤΥ饤�֥��⥸�塼�뤬���ʤ��Υ����ƥ��ɸ��ȤʤäƤ��뤫�� �ؤ֤���ˤ� L �򻲾Ȥ��Ƥ��������� ���֥������ȥ᥽�åɸƤӽФ��κ������ؤ֤ˤ� L �� ���Ȥ��Ƥ��������� =begin meta Translate: KIMURA Koichi (5.005_03) Update: SHIRAKATA Kentaro (5.6.1-) Status: completed =end meta