=encoding euc-jp =head1 NAME X =begin original perlsyn - Perl syntax =end original perlsyn - Perl ��ʸˡ =head1 DESCRIPTION =begin original A Perl program consists of a sequence of declarations and statements which run from the top to the bottom. Loops, subroutines, and other control structures allow you to jump around within the code. =end original Perl �ץ������ϡ������ʸ���¤Ӥ��鹽�����졢�夫�鲼�ؤȼ¹Ԥ���ޤ��� �롼�ס����֥롼���󡢤���¾�����浡���ǥ����ɤο����ʤȤ����� �����פǤ��ޤ��� =begin original Perl is a B language: you can format and indent it however you like. Whitespace serves mostly to separate tokens, unlike languages like Python where it is an important part of the syntax, or Fortran where it is immaterial. =end original Perl �� B<��ͳ��> ����Ǥ�: �����ʤ褦�����������ꥤ��ǥ�Ȥ����� �Ǥ��ޤ��� ����ʸˡ�ν��פ����ǤǤ��� Python �䡢��̣�Τʤ� Fortran �Τ褦�ʸ���� �ۤʤꡢ����ϤۤȤ�ɥȡ������ʬ������ܤǤ��� =begin original Many of Perl's syntactic elements are B. Rather than requiring you to put parentheses around every function call and declare every variable, you can often leave such explicit elements off and Perl will figure out what you meant. This is known as B, abbreviated B. It allows programmers to be B and to code in a style with which they are comfortable. =end original Perl ��¿����ʸˡ���Ǥ� B<��ά��ǽ> �Ǥ��� ���Ƥδؿ��򤫤ä��dz�ä��ꡢ���Ƥ��ѿ�����������ꤹ�뤳�Ȥ� �׵᤹��ΤǤϤʤ������Ф��Ф��Τ褦������Ū�����Ǥ��֤��Ƥ����ơ� Perl �ˤ��ʤ�����̣���Ƥ���Ȥ����򸫤Ĥ��Ф����뤳�Ȥ��Ǥ��ޤ��� ����� B ���Τ�졢Ƭʸ�����ä� B �ȸƤФ�ޤ��� ����ˤ�äơ��ץ�����ޤ� B<����> �ˤǤ�����餬��Ŭ���Ȼפ���������� �����ǥ��󥰤Ǥ���褦�ˤ��ޤ��� =begin original Perl B and concepts from many languages: awk, sed, C, Bourne Shell, Smalltalk, Lisp and even English. Other languages have borrowed syntax from Perl, particularly its regular expression extensions. So if you have programmed in another language you will see familiar pieces in Perl. They often work the same, but see L for information about how they differ. =end original Perl �ϡ�awk, sed, C, Bourne Shell, Smalltalk, Lisp, �̤ƤϱѸ�Ȥ��ä��� ¿���θ��줫�饳�󥻥ץȤ� B<ʸˡ�����> ���Ƥ��ޤ��� ¾�θ���� Perl ����ʸˡ����Ѥ��Ƥ��ޤ�; �ä�����ɽ����ĥ��Ǥ��� ���äơ�¾�θ���ǥץ�����ߥ󥰤��Ƥ����ʤ顢Perl �ˤ⸫�����Ȥ�����褦�� ��Τ�����Ǥ��礦�� �����Ϥ��Ф���Ʊ���褦��ư��ޤ������㤦���ˤĤ��Ƥξ���� L �򻲾Ȥ��Ƥ��������� =head2 Declarations X X X X (���) =begin original The only things you need to declare in Perl are report formats and subroutines (and sometimes not even subroutines). A scalar variable holds the undefined value (C) until it has been assigned a defined value, which is anything other than C. When used as a number, C is treated as C<0>; when used as a string, it is treated as the empty string, C<"">; and when used as a reference that isn't being assigned to, it is treated as an error. If you enable warnings, you'll be notified of an uninitialized value whenever you treat C as a string or a number. Well, usually. Boolean contexts, such as: =end original Perl �������ɬ�פʤ�Τϥ�ݡ��ȥե����ޥåȤȥ��֥롼��������Ǥ� (���֥롼���󤹤���������פʾ��⤢��ޤ�)�� �������ѿ��ϡ�C �ʳ���������줿�ͤ����������ޤǤ�̤����� (C)�Ȥʤ�ޤ��� ���ͤȤ��ƻȤ����硢C �� C<0> �Ȥ��ư����ޤ�; ʸ����Ȥ��ƻȤ����硢����϶�ʸ���� C<""> �Ȥ��ư����ޤ�; ��ե���󥹤Ȥ��ƻȤ����硢����ϲ�����������Ƥ��ʤ��Τǡ����顼�Ȥ��� �����ޤ��� �ٹ��ͭ���ˤ��Ƥ���ʤ顢C ��ʸ�������ͤȤ��ư������Ȥ���� ̤������ͤ��Ŧ����ޤ��� ���������̤ϡ� ���Τ褦�ʿ����ͥ���ƥ����Ȥʤ�: if ($a) {} =begin original are exempt from warnings (because they care about truth rather than definedness). Operators such as C<++>, C<-->, C<+=>, C<-=>, and C<.=>, that operate on undefined variables such as: =end original (����Ѥߤ��ɤ����ǤϤʤ��������ɤ������θ����Τ�)�ٹ𤫤��Ȥ�ޤ��� ̤������ѿ������롢C<++>, C<-->, C<+=>, C<-=>, C<.=> �Τ褦�� �黻�ҤǤ�: undef $a; $a++; =begin original are also always exempt from such warnings. =end original �Ȥ��뤳�ȤǤ⤽�Τ褦�ʷٹ𤫤��Ȥ�ޤ��� =begin original A declaration can be put anywhere a statement can, but has no effect on the execution of the primary sequence of statements: declarations all take effect at compile time. All declarations are typically put at the beginning or the end of the script. However, if you're using lexically-scoped private variables created with C, C, or C, you'll have to make sure your format or subroutine definition is within the same block scope as the my if you expect to be able to access those private variables. =end original ����ϡ�ʸ���֤���Ȥ����Ǥ���Фɤ��ˤǤ��֤����Ȥ��Ǥ��ޤ����� ����Ū��ʸ���¤Ӥϼ¹Ի��ˤϲ��θ��̤�����ޤ���: ����ϥ���ѥ������ ���٤Ƥθ��̤�ɽ��ޤ��� ŵ��Ū�ˤϤ��٤Ƥ�����ϡ�������ץȤ���Ƭ����ü���֤���ޤ��� �������ʤ��顢�ɽ��ѿ��� C,C, or C ��Ȥäƺ������� �쥭������ʥ������פ�ȤäƤ���ΤǤ���С��ե����ޥåȤ䥵�֥롼����� �����Ʊ���֥��å��Υ������פ���Ǥ��ζɽ��ѿ��˥����������뤳�Ȥ� ��ǽ�Ǥ���褦�ˤ��Ƥ���ɬ�פ�����Ǥ��礦�� =begin original Declaring a subroutine allows a subroutine name to be used as if it were a list operator from that point forward in the program. You can declare a subroutine without defining it by saying C, thus: X =end original ���֥롼���������ϡ��ץ������θ�Τۤ��ˤ��륵�֥롼����̾�� �ꥹ�ȱ黻�ҤΤ褦�˻Ȥ����Ȥ�����ޤ��� �������Ƥ��ʤ����֥롼����������C �ȵ��Ҥ��뤳�Ȥ� ����Ǥ���Τǡ��ʲ��Τ褦�ˤǤ��ޤ�: X sub myname; $me = myname $0 or die "can't get myname"; =begin original A bare declaration like that declares the function to be a list operator, not a unary operator, so you have to be careful to use parentheses (or C instead of C<||>.) The C<||> operator binds too tightly to use after list operators; it becomes part of the last element. You can always use parentheses around the list operators arguments to turn the list operator back into something that behaves more like a function call. Alternatively, you can use the prototype C<($)> to turn the subroutine into a unary operator: =end original �ؿ�������Τ褦���������ϥꥹ�ȱ黻�ҤΤ褦��Ư���ΤǤ��ꡢ ñ��黻�ҤȤ��ƤǤϤ���ޤ���; �Ǥ����顢���ä� (�ޤ��� C<||> ������� C) ��Ȥ����Ȥˤ����դ��Ƥ��������� C<||> �黻�Ҥϥꥹ�ȱ黻�Ҥθ���˻Ȥ��ˤ�«�����������ޤ�; �Ǹ�����Ǥ� �����ˤʤ�ޤ��� �ꥹ�ȱ黻�Ҥμ���򤫤ä��ǰϤळ�ȤǤ��ĤǤ�ꥹ�ȱ黻�Ҥ� �ؿ��ƤӽФ��Τ褦�˿�����碌��褦�ˤǤ��ޤ��� ���뤤�ϡ����֥롼�����ñ��黻�Ҥ��Ѥ��뤿��˥ץ��ȥ����� C<($)> ��Ȥ��ޤ�: sub myname ($); $me = myname $0 || die "can't get myname"; =begin original That now parses as you'd expect, but you still ought to get in the habit of using parentheses in that situation. For more on prototypes, see L. =end original �����ͽ�ۤ����̤�˥ѡ������ޤ���������Ǥ⤳�Τ褦�ʾ��ˤϤ��ä���Ȥ� �������դ���٤��Ǥ��� �ץ��ȥ����פ˴ؤ��Ƥ���ʤ����ϡ�L �򻲾Ȥ��Ƥ��������� =begin original Subroutines declarations can also be loaded up with the C statement or both loaded and imported into your namespace with a C statement. See L for details on this. =end original ���֥롼���������� C ʸ��ȤäƵͤ���ळ�Ȥ�Ǥ��ޤ����� C ʸ��ȤäƼ�ʬ��̾�����֤˥����ɤ����ꥤ��ݡ��Ȥ����ꤹ�뤳�Ȥ� �Ǥ��ޤ��� ����˴ؤ���ܺ٤� L �򻲾Ȥ��Ƥ��������� =begin original A statement sequence may contain declarations of lexically-scoped variables, but apart from declaring a variable name, the declaration acts like an ordinary statement, and is elaborated within the sequence of statements as if it were an ordinary statement. That means it actually has both compile-time and run-time effects. =end original ʸ���¤Ӥϥ쥭�����륹�����פ���ä��ѿ��������ޤळ�Ȥ��Ǥ��ޤ����� �ѿ�̾������Ȥ��ڤ�Υ���졢����������̾��ʸ�Τ褦�˿����񤤡� ���줬�̾��ʸ�Ǥ��뤫�Τ褦��ʸ���¤Ӥ��Ȥߤ��ޤ�ޤ��� ����ϡ��������ä����������ѥ�����θ��̤ȼ¹Ի��θ��̤�ξ���� ���äƤ���Ȥ������ȤǤ��� =head2 Comments X X<#> (������) =begin original Text from a C<"#"> character until the end of the line is a comment, and is ignored. Exceptions include C<"#"> inside a string or regular expression. =end original �����Ȥ� C<"#"> ʸ�����顢�����ޤ�³����������ʬ��̵�뤵��ޤ��� �㳰�ϡ�ʸ���������ɽ������ˤ��� C<"#"> �Ǥ��� =head2 Simple Statements X X X X<;> (ñ��ʸ) =begin original The only kind of simple statement is an expression evaluated for its side-effects. Every simple statement must be terminated with a semicolon, unless it is the final statement in a block, in which case the semicolon is optional. But put the semicolon in anyway if the block takes up more than one line, because you may eventually add another line. Note that there are operators like C, C, and C that I like compound statements, but aren't--they're just TERMs in an expression--and thus need an explicit termination when used as the last item in a statement. =end original ñ��ʸ�Ȥʤ�ͣ��μ���ϡ����������ѤΤ����ɾ������뼰�Ǥ��� ���٤Ƥ�ñ��ʸ�ϡ����줬���ߥ�������ά���뤳�ȤΤǤ���֥��å��� �Ǹ�ˤʤ��¤��ʸ��ü���뤿��Υ��ߥ����󤬤ʤ���Фʤ�ޤ��� �֥��å�����԰ʾ���Ϥ���ˤϡ��Ȥˤ������ߥ�������դ��Ƥ�������; �ʤ��ʤ顢�̤ιԤ��ɲä����ǽ�������뤫��Ǥ��� C, C, C �Τ褦�ˡ��츫ʣ��ʸ�Τ褦�� I<������> ����ɤ� �����ǤϤʤ�--������ñ�ʤ뼰�ˤ����� TERM �Ǥ�--��Τ����äơ� �������ä���Τ�ʸ�κǸ�Υ����ƥ�Ȥ��ƻȤä����ˤ�����Ū�˽�ü���� ɬ�פ�����Τ��Ȥ������Ȥ����դ��Ƥ��������� =head2 Truth and Falsehood X X X X X X X X<0> (������) =begin original The number 0, the strings C<'0'> and C<"">, the empty list C<()>, and C are all false in a boolean context. All other values are true. Negation of a true value by C or C returns a special false value. When evaluated as a string it is treated as C<"">, but as a number, it is treated as 0. Most Perl operators that return true or false behave this way. =end original ���� 0, ʸ���� C<'0'> �� C<"">, ���ꥹ�� C<()>, C �����ƿ����� ����ƥ����ȤǤϵ��Ȥʤ�ޤ��� ����¾�����Ƥ��ͤϿ��Ǥ��� �����ͤ� C �� C �����ꤹ��ȡ��ü�ʵ����ͤ��֤��ޤ��� �����ʸ����Ȥ���ɾ������� C<""> �Ȥ��ư����ޤ��������ͤȤ���ɾ������� 0 �Ȥ��ư����ޤ��� ���ޤ��ϵ����֤����ۤȤ�� Perl �α黻�ҤϤ��Τ褦�˿����񤤤ޤ��� =head2 Statement Modifiers X X X X X X X X X (ʸ������) =begin original Any simple statement may optionally be followed by a I modifier, just before the terminating semicolon (or block ending). The possible modifiers are: =end original Ǥ�դ�ñ��ʸ�ˤϡ�B<���> �ν����Ҥ�ü�Υ��ߥ������ľ��(�⤷���� �֥��å��ν�ü��ľ��)���դ��뤳�Ȥ��Ǥ��ޤ��� �Ȥ����ȤΤǤ��뽤���Ҥϰʲ����̤�Ǥ��� if EXPR unless EXPR while EXPR until EXPR for LIST foreach LIST when EXPR =begin original The C following the modifier is referred to as the "condition". Its truth or falsehood determines how the modifier will behave. =end original �����Ҥ˰���³�� C �ϡ־��פȤ��ƻ��Ȥ���ޤ��� ���ο����ͤ������Ҥο����񤤤���ꤷ�ޤ��� =begin original C executes the statement once I and only if the condition is true. C is the opposite, it executes the statement I the condition is true (that is, if the condition is false). =end original C �� I<�⤷> ��郎���ξ��ˤΤ�ʸ��¹Ԥ��ޤ��� C �ϵդǡ���郎�� I<�Ǥʤ��¤�> (�Ĥޤꡢ��郎���ʤ�) ʸ�� �¹Ԥ��ޤ��� print "Basset hounds got long ears" if length $ear >= 10; go_outside() and play() unless $is_raining; =begin original The C modifier is an iterator: it executes the statement once for each item in the LIST (with C<$_> aliased to each item in turn). =end original C �����Ҥ�ȿ���ҤǤ�: LIST ���ͤ��줾�����ʸ��¹Ԥ��ޤ�(�¹���� C<$_> �����줾����ͤ� �����ꥢ���Ȥʤ�ޤ�)�� print "Hello $_!\n" for qw(world Dolly nurse); =begin original C repeats the statement I the condition is true. C does the opposite, it repeats the statement I the condition is true (or while the condition is false): =end original C �Ͼ�郎�� I<�δ�> ʸ�򷫤��֤��ޤ��� C �ϵդǡ���郎�� I<�ˤʤ�ޤ�> (�Ĥޤ��郎���δ�) ʸ�� �����֤��ޤ�: # Both of these count from 0 to 10. print $i++ while $i <= 10; print $j++ until $j > 10; =begin original The C and C modifiers have the usual "C loop" semantics (conditional evaluated first), except when applied to a C-BLOCK (or to the Perl4 C-SUBROUTINE statement), in which case the block executes once before the conditional is evaluated. =end original ������ C �� C �ϡ�����Ū�� "C loop" �ΰ�̣�� ���äƤ��ޤ�(��郎�ǽ��ɾ�������)����C-�֥��å�(�⤷���� Perl4 �� C-���֥롼����ʸ)��Ŭ�Ѥ����Ȥ����㳰�ǡ� ���ΤȤ��Ͼ�郎ɾ�������������ˡ����٥֥��å����¹Ԥ���ޤ��� =begin original This is so that you can write loops like: =end original ���Τ��ᡢ���Τ褦�ʥ롼�פ򵭽Ҥ��뤳�Ȥ��Ǥ��ޤ�: do { $line = ; ... } until !defined($line) || $line eq ".\n" =begin original See L. Note also that the loop control statements described later will I work in this construct, because modifiers don't take loop labels. Sorry. You can always put another block inside of it (for C) or around it (for C) to do that sort of thing. For C, just double the braces: X X X =end original L �򻲾Ȥ��Ƥ��������� ��Ҥ���롼�פ�����ʸ�ϡ������Ҥ��롼�ץ�٥����ʤ������ ���ι�¤ʸ�Ǥ� I<ư��ʤ�> �Ȥ������Ȥˤ����դ��Ƥ��������� �������ʤ��� �������ä������н褹��Τ��̤Υ֥��å�����¦�����줿��(C �ξ��)�� �̤Υ֥��å��ǰϤ�(C �ξ��)�Ȥ�����ˡ����˻Ȥ��ޤ��� C �Ǥ�ñ���椫�ä�����Ťˤ��ޤ�: X X X do {{ next if $x == $y; # do something here }} until $x++ > $z; =begin original For C, you have to be more elaborate: X =end original C �ξ��ϡ���ä�ǰ����ˤ���ɬ�פ�����ޤ�: LOOP: { do { last if $x = $y**2; # do something here } while $x++ <= $z; } =begin original B The behaviour of a C, C, or C modified with a statement modifier conditional or loop construct (for example, C) is B. The value of the C variable may be C, any previously assigned value, or possibly anything else. Don't rely on it. Future versions of perl might do something different from the version of perl you try it out on. Here be dragons. X =end original B<����:> (C �Τ褦��) ��ﹽ¤��롼�׹�¤�ǽ������줿 C C,C ʸ�ο����񤤤� B<̤���> �Ǥ��� C �ѿ����ͤ� C �����Τ�ޤ��󤷡��������������줿�ͤ��� �Τ�ޤ��󤷡�����¾��ǡ���ʤ��ͤβ�ǽ���⤢��ޤ��� �����ͤ˰�¸���ƤϤ����ޤ��� perl �ξ���ΥС������Ǥϸ��ߤΥС������Ȥϲ����㤦�����Τ�ޤ��� �����ˤ����ʤ�Τ����ޤ��� X =begin original The C modifier is an experimental feature that first appeared in Perl 5.14. To use it, you should include a C declaration. (Technically, it requires only the C feature, but that aspect of it was not available before 5.14.) Operative only from within a C loop or a C block, it executes the statement only if the smartmatch C<< $_ ~~ I >> is true. If the statement executes, it is followed by a C from inside a C and C from inside a C. =end original C �����Ҥ� Perl 5.14 �Ǻǽ�˸��줿�¸�Ū��ǽ�Ǥ��� �Ȥ��ˤϡ�C �����ޤ�ޤ��� (����Ū�ˤϡ�C ��ǽ������ɬ�פǤ��������δ����Ǥ� 5.14 ������Ǥ� ���ѤǤ��ޤ���) C �롼�פ� C �֥��å�����¦�ǤΤ�ư���ǽ�ǡ� ���ޡ��ȥޥå��� C<< $_ ~~ I >> �����ξ��ˤΤ߼¹Ԥ���ޤ��� ʸ���¹Ԥ����ȡ�C ����¦����� C �ˡ�C �� ��¦����� C �˰���³���ޤ��� =begin original Under the current implementation, the C loop can be anywhere within the C modifier's dynamic scope, but must be within the C block's lexical scope. This restricted may be relaxed in a future release. See L<"Switch Statements"> below. =end original ���ߤμ����Ǥϡ�C �롼�פ� C �����Ҥ�ưŪ�������פ���¦�� �ɤ��Ǥ�Ȥ��ޤ�����C �֥��å��Υ쥭�����륹�����פ���¦�� �ʤ���Фʤ�ޤ��� �������¤Ͼ���Υ�꡼���Ǵ��¤���뤫�⤷��ޤ��� ��Ҥ��� L<"Switch Statements"> �򻲾Ȥ��Ƥ��������� =head2 Compound Statements X X X X X X<{> X<}> X X X X X X X X (ʣ��ʸ) =begin original In Perl, a sequence of statements that defines a scope is called a block. Sometimes a block is delimited by the file containing it (in the case of a required file, or the program as a whole), and sometimes a block is delimited by the extent of a string (in the case of an eval). =end original Perl �Ǥϡ��������פ��������褦��ʸ���¤Ӥ�֥��å��ȸƤӤޤ��� �֥��å��Ϥ����ޤ�ե�����ˤ�ä��ϰϤ������뤳�Ȥ�����ޤ� (�ե����뤬 require ���줿�Ȥ������ץ���������ΤȤ��Ƥξ��)���� ʸ�����Ÿ���ˤ�ä��ϰϤ�������(eval �ξ��)���Ȥ⤢��ޤ��� =begin original But generally, a block is delimited by curly brackets, also known as braces. We will call this syntactic construct a BLOCK. =end original ����������Ū�ˤϡ��֥��å����椫�ä��ˤ�ä��ϰϤ������ޤ��� ���ι�ʸŪ�ʹ�¤��֥��å��ȸƤӤޤ��� =begin original The following compound statements may be used to control flow: =end original �ʲ��˵󤲤�ʣ��ʸ������ե����Ȥ��ƻȤ����Ȥ��Ǥ��ޤ�: if (EXPR) BLOCK if (EXPR) BLOCK else BLOCK if (EXPR) BLOCK elsif (EXPR) BLOCK ... if (EXPR) BLOCK elsif (EXPR) BLOCK ... else BLOCK unless (EXPR) BLOCK unless (EXPR) BLOCK else BLOCK unless (EXPR) BLOCK elsif (EXPR) BLOCK ... unless (EXPR) BLOCK elsif (EXPR) BLOCK ... else BLOCK given (EXPR) BLOCK LABEL while (EXPR) BLOCK LABEL while (EXPR) BLOCK continue BLOCK LABEL until (EXPR) BLOCK LABEL until (EXPR) BLOCK continue BLOCK LABEL for (EXPR; EXPR; EXPR) BLOCK LABEL for VAR (LIST) BLOCK LABEL for VAR (LIST) BLOCK continue BLOCK LABEL foreach (EXPR; EXPR; EXPR) BLOCK LABEL foreach VAR (LIST) BLOCK LABEL foreach VAR (LIST) BLOCK continue BLOCK LABEL BLOCK LABEL BLOCK continue BLOCK PHASE BLOCK =begin original The experimental C statement is I; see L below for how to do so, and the attendant caveats. =end original �¸�Ū�� C ʸ�� I<��ưŪ�ˤ�ͭ���ˤʤ�ޤ���>; �������뤿��� ��ˡ�ȡ��տ魯���������ˤĤ��Ƥϸ�Ҥ��� L �� ���Ȥ��Ƥ��������� =begin original Unlike in C and Pascal, in Perl these are all defined in terms of BLOCKs, not statements. This means that the curly brackets are I--no dangling statements allowed. If you want to write conditionals without curly brackets, there are several other ways to do it. The following all do the same thing: =end original C �� Pascal �ȤϰۤʤꡢPerl �Ǥϥ֥��å�����褦�� �������Ƥ���ʸ����ΤǤϤ���ޤ��� �Ĥޤꡢ�椫�ä��� I<ɬ�פʤ��> �Ǥ� -- ۣ���ʸ��������ޤ��� �椫�ä��ʤ��ξ��ʸ��Ȥ������ΤǤ���С������Ĥ��Τ����������ޤ��� �ʲ������Ƥ�Ʊ�����ȤǤ�: if (!open(FOO)) { die "Can't open $FOO: $!" } die "Can't open $FOO: $!" unless open(FOO); open(FOO) || die "Can't open $FOO: $!"; open(FOO) ? () : die "Can't open $FOO: $!"; # a bit exotic, that last one =begin original The C statement is straightforward. Because BLOCKs are always bounded by curly brackets, there is never any ambiguity about which C an C goes with. If you use C in place of C, the sense of the test is reversed. Like C, C can be followed by C. C can even be followed by one or more C statements, though you may want to think twice before using that particular language construct, as everyone reading your code will have to think at least twice before they can understand what's going on. =end original C ʸ������Ǥ��� �֥��å��Ͼ���椫�ä��Ƕ��ڤ���Τǡ�C �� C ���б��� ۣ��ˤʤ�褦�ʤ��ȤϷ褷�Ƥ���ޤ��� C �� C ������˻Ȥ��ȡ�������ȿž���ޤ��� C ��Ʊ�͡�C �� C �˰���³�����Ȥ��Ǥ��ޤ��� C �ϰ�Ĥޤ��Ϥ���ʾ�� C �˰���³�����Ȥ���Ǥ��ޤ����� ��������θ��칽ʸ��Ȥ��������ܹͤ������Ǥ��礦; ���ʤ��Υ����ɤ��ɤ� ï�⤬�����Ԥ��Ƥ���Τ������򤹤����˾��ʤ��Ȥ����ܹͤ���ɬ�פ� ���뤫��Ǥ��� =begin original The C statement executes the block as long as the expression is L. The C statement executes the block as long as the expression is false. The LABEL is optional, and if present, consists of an identifier followed by a colon. The LABEL identifies the loop for the loop control statements C, C, and C. If the LABEL is omitted, the loop control statement refers to the innermost enclosing loop. This may include dynamically looking back your call-stack at run time to find the LABEL. Such desperate behavior triggers a warning if you use the C pragma or the B<-w> flag. =end original C ʸ�ϡ����� L<��|/"Truth and Falsehood"> �Ǥ���֡��֥��å��� �¹Ԥ��ޤ��� C ʸ�ϡ��������Ǥ���֡��֥��å���¹Ԥ��ޤ��� LABEL �Ͼ�ά��ǽ�Ǥ�����������ˤϡ��������ȼ�ä����̻Ҥˤʤ�ޤ��� LABEL �� C��C��C �Ȥ��ä��롼������ʸ�Υ롼�פ��ꤷ�ޤ��� LABEL ����ά���줿��硢�롼������ʸ�Ϥ����ޤ�롼�פ���ǺǤ���¦�� �롼�פ򻲾Ȥ��ޤ��� ����ϡ��¹Ի��� LABEL �򸡽Ф��뤿��θƤӽФ������å���ưŪ�ʸ���긡���� �ޤळ�Ȥ��Ǥ��ޤ��� ���Τ褦�ʿ侩����ʤ������񤤤ϡ�C �ץ饰�ޤ� B<-w> �ե饰�� �Ȥä����ˤϷٹ������������ޤ��� =begin original If there is a C BLOCK, it is always executed just before the conditional is about to be evaluated again. Thus it can be used to increment a loop variable, even when the loop has been continued via the C statement. =end original C �֥��å���¸�ߤ����硢 ��˾�郎��ɾ�������ľ���˼¹Ԥ���ޤ��� �������äơ����Υ֥��å���롼���ѿ��Υ��󥯥���ȤΤ���� �Ȥ����Ȥ��Ǥ��ޤ�; ����ϡ��롼�פ�Cʸ���̤��Ʒ�³�����Ȥ��Ǥ�¹Ԥ���ޤ��� =begin original When a block is preceding by a compilation phase keyword such as C, C, C, C, or C, then the block will run only during the corresponding phase of execution. See L for more details. =end original �֥��å������� C, C, C, C, C �Τ褦�� ����ѥ���ե�����������ɤ����֤����ȡ��֥��å����б�����¹ԥե������� �֤ˤ����¹Ԥ���ޤ��� ����ʤ�ܺ٤ˤĤ��Ƥ� L �򻲾Ȥ��Ƥ��������� =begin original Extension modules can also hook into the Perl parser to define new kinds of compound statements. These are introduced by a keyword which the extension recognizes, and the syntax following the keyword is defined entirely by the extension. If you are an implementor, see L for the mechanism. If you are using such a module, see the module's documentation for details of the syntax that it defines. =end original �������ƥ󥷥��⥸�塼��Ͽ����������ʣ��ʸ��������뤿��� Perl �ѡ�����եå��Ǥ��ޤ��� �����ϥ������ƥ󥷥��ǧ�����륭����ɤ�Ƴ�����졢������ɤ� ����³��ʸˡ�ϴ����˥������ƥ󥷥����������ޤ��� �⤷���ʤ��������֤ʤ顢���ȤߤˤĤ��Ƥ� L �� ���Ȥ��Ƥ��������� ���ʤ������Τ褦�ʥ⥸�塼���Ȥ��ʤ顢�������Ƥ���ʸˡ�ξܺ٤ˤĤ��Ƥ� ���Υ⥸�塼���ʸ��򻲾Ȥ��Ƥ��������� =head2 Loop Control X X X X X X (�롼������) =begin original The C command starts the next iteration of the loop: =end original C ���ޥ�ɤϥ롼�פμ��η����֤��򳫻Ϥ��ޤ�: LINE: while () { next LINE if /^#/; # discard comments ... } =begin original The C command immediately exits the loop in question. The C block, if any, is not executed: =end original C ���ޥ�ɤϥ롼�פ���¨�¤�æ�Ф��ޤ��� C �֥��å������äƤ⡢����ϼ¹Ԥ���ޤ���: LINE: while () { last LINE if /^$/; # exit when done with header ... } =begin original The C command restarts the loop block without evaluating the conditional again. The C block, if any, is I executed. This command is normally used by programs that want to lie to themselves about what was just input. =end original C ���ޥ�ɤϡ����κ�ɾ���򤹤뤳�Ȥʤ��˥롼�ץ֥��å��� �Ƽ¹Ԥ�Ԥ��ޤ��� C �֥��å������äƤ⡢����� I<�¹Ԥ���ޤ���>�� ���Υ��ޥ�ɤ��̾�ץ��������Ф������Ϥ˴ؤ��ƥץ�����༫�Ȥ� ���ޤ������Ȥ��ä��Ȥ��˻Ȥ��ޤ��� =begin original For example, when processing a file like F. If your input lines might end in backslashes to indicate continuation, you want to skip ahead and get the next record. =end original ���Ȥ��С�F �Τ褦�ʥե������������뤳�Ȥ� �ͤ��Ƥߤޤ��礦�� �⤷���Ϥ��줿�Ԥι�������³�򼨤��Хå�����å���Ǥ��ä���硢��ؿʤ�� ���Υ쥳���ɤ���Ф������Ȼפ��Ǥ��礦�� while (<>) { chomp; if (s/\\$//) { $_ .= <>; redo unless eof(); } # now process $_ } =begin original which is Perl shorthand for the more explicitly written version: =end original ����� Perl �ξ�ά��ˡ�ǡ���äȤϤä���Ƚ񤯤Ȱʲ��Τ褦�ˤʤ�ޤ�: LINE: while (defined($line = )) { chomp($line); if ($line =~ s/\\$//) { $line .= ; redo LINE unless eof(); # not eof(ARGV)! } # now process $line } =begin original Note that if there were a C block on the above code, it would get executed only on lines discarded by the regex (since redo skips the continue block). A continue block is often used to reset line counters or C one-time matches: =end original �嵭����� C �֥��å������ä��Ȥ����顢����� (redo �� continue �֥��å��򥹥��åפ���Τ�) ����ɽ���ˤ�ä� �ΤƤ�줿�Ԥ������¹Ԥ����Ȥ������Ȥ����դ��Ƥ��������� continue �֥��å��Ϲԥ����󥿡���ꥻ�åȤ���Ȥ��� ���٤����ޥå����� C ��ꥻ�åȤ���Τ˻Ȥ��ޤ��� # inspired by :1,$g/fred/s//WILMA/ while (<>) { m?(fred)? && s//WILMA $1 WILMA/; m?(barney)? && s//BETTY $1 BETTY/; m?(homer)? && s//MARGE $1 MARGE/; } continue { print "$ARGV $.: $_"; close ARGV if eof; # reset $. reset if eof; # reset ?pat? } =begin original If the word C is replaced by the word C, the sense of the test is reversed, but the conditional is still tested before the first iteration. =end original C �� C ���֤���������縡���ΰ�̣�ϵ�ž���ޤ����� �����֤����¹Ԥ���������˾�郎��������뤳�Ȥ��Ѥ�ꤢ��ޤ��� =begin original Loop control statements don't work in an C or C, since they aren't loops. You can double the braces to make them such, though. =end original �롼������ʸ�� C �� C ��Ǥ�ư��ޤ���; �ʤ��ʤ餽���ϥ롼�פǤϤʤ�����Ǥ��� �������椫�ä�����Ťˤ��Ƥ�����н褹�뤳�ȤϤǤ��ޤ��� if (/pattern/) {{ last if /fred/; next if /barney/; # same effect as "last", # but doesn't document as well # do something here }} =begin original This is caused by the fact that a block by itself acts as a loop that executes once, see L<"Basic BLOCKs">. =end original ����ϡ��֥��å����Ȥϰ��٤����¹Ԥ����롼�פȤ���ư��뤫��Ǥ�; L<"Basic BLOCKs"> �򻲾Ȥ��Ƥ��������� =begin original The form C, available in Perl 4, is no longer available. Replace any occurrence of C by C. =end original Perl 4 �ǤϻȤ����ȤΤǤ��� C �Ȥ��������ϡ� ��Ϥ�Ȥ����Ȥ��Ǥ��ޤ��� C ����ʬ�� C ���֤������Ƥ��������� =head2 For Loops X X (for �롼��) =begin original Perl's C-style C loop works like the corresponding C loop; that means that this: =end original Perl �� C ������ C �롼�פϡ��б����� C �롼�פ�Ʊ�ͤ� ư��ޤ�; �Ĥޤꡢ�ʲ��Τ�Τ�: for ($i = 1; $i < 10; $i++) { ... } =begin original is the same as this: =end original �ʲ��Τ�Τ�Ʊ���Ǥ�: $i = 1; while ($i < 10) { ... } continue { $i++; } =begin original There is one minor difference: if variables are declared with C in the initialization section of the C, the lexical scope of those variables is exactly the C loop (the body of the loop and the control sections). X =end original �����ʰ㤤����Ĥ���ޤ�: C �ν�������� C ��Ȥä��ѿ��� ������줿��硢�����ѿ��Υ쥭�����륹�����פ� C �롼�� (�롼�����Τ�������) �ȴ�����Ʊ���Ǥ��� X =begin original As a special case, if the test in the C loop (or the corresponding C loop) is empty, it is treated as true. That is, both =end original ���̤ʾ��Ȥ��ơ��⤷ C �롼�� (�ޤ����б����� C �롼��) �� �ƥ��Ȥ����ʤ顢���Ȥ��ư����ޤ��� �Ĥޤꡢ���Τ�� for (;;) { ... } =begin original and =end original ����� while () { ... } =begin original are treated as infinite loops. =end original ��̵�¥롼�פȤ��ư����ޤ��� =begin original Besides the normal array index looping, C can lend itself to many other interesting applications. Here's one that avoids the problem you get into if you explicitly test for end-of-file on an interactive file descriptor causing your program to appear to hang. X X X =end original �̾�Ρ�������Ф���ź�����դ��Υ롼�פΤۤ��ˤ⡢C ��¾�� ¿���ζ�̣�������ץꥱ�������Τ���˼��Ѥ��뤳�Ȥ��Ǥ��ޤ��� �ʲ�����ϡ�����Ū�ʥե����뵭�һҤν�ü������Ū�˸������Ƥ��ޤ��� �ץ�������ϥ󥰥��åפ����褦�˸����Ƥ��ޤ��������򤹤��ΤǤ��� X X X $on_a_tty = -t STDIN && -t STDOUT; sub prompt { print "yes? " if $on_a_tty } for ( prompt(); ; prompt() ) { # do something } =begin original Using C (or the operator form, C<< >>) as the conditional of a C loop is shorthand for the following. This behaviour is the same as a C loop conditional. X X<< <> >> =end original C �롼�פξ��Ȥ��� C (�ޤ��ϱ黻�ҷ����� C<< >>) �� �Ȥ���硢�ʲ��Τ褦�˾�ά�����Ȥ��ޤ��� ���ο����񤤤� C �롼�׾���Ʊ���Ǥ��� X X<< <> >> for ( prompt(); defined( $_ = ); prompt() ) { # do something } =head2 Foreach Loops X X (foreach �롼��) =begin original The C loop iterates over a normal list value and sets the variable VAR to be each element of the list in turn. If the variable is preceded with the keyword C, then it is lexically scoped, and is therefore visible only within the loop. Otherwise, the variable is implicitly local to the loop and regains its former value upon exiting the loop. If the variable was previously declared with C, it uses that variable instead of the global one, but it's still localized to the loop. This implicit localization occurs I in a C loop. X X =end original C �롼�פ� �̾�Υꥹ���ͤ��Ф��Ƥη����֤���Ԥ����ѿ� VAR �� �ꥹ�Ȥ����Ǥ򷫤��֤����˰�Ĥ��ĥ��åȤ��ޤ��� �ѿ������� C �Ȥ���������ɤ��֤���Ƥ�����硢�����ѿ��� �쥭�����륹�����פ�������������äƤ���ϥ롼�פ���ǤΤ߲Ļ�Ȥʤ�ޤ��� ���Υ�����ɤ��ʤ���С��ѿ��ϥ롼�פ��Ф��ƥ�������Ȥʤꡢ�롼�פ� ȴ������ǰ������ͤ����ټ�������ޤ��� �ѿ��������� C ��Ȥä��������Ƥ����ʤ�С��������Х�ʤ�Τ� ����ˤ����ѿ���Ȥ��ޤ����������롼�פ˥�������ʤ�ΤȤʤ�ޤ��� ���ΰ��ۤΥ������벽�� C ����� I<�Τ�> �����ޤ��� X X =begin original The C keyword is actually a synonym for the C keyword, so you can use either. If VAR is omitted, C<$_> is set to each value. X<$_> =end original C �ϼºݤˤ� C ��Ʊ����ʤΤǡ��ɤ���Ǥ�Ȥ��ޤ��� VAR ����ά���줿���ˤϡ�C<$_> ���ͤ����ꤵ��ޤ��� X<$_> =begin original If any element of LIST is an lvalue, you can modify it by modifying VAR inside the loop. Conversely, if any element of LIST is NOT an lvalue, any attempt to modify that element will fail. In other words, the C loop index variable is an implicit alias for each item in the list that you're looping over. X =end original LIST �����Ǥ������ͤǤ��ä���硢�롼�פ���� VAR ���ѹ����뤳�Ȥˤ�ꡢ �б������ͤ��ѹ����뤳�Ȥ��Ǥ��ޤ��� �դˡ�LIST �����Ǥ������ͤǤʤ����ϡ��������Ǥ������褦�Ȥ��Ƥ� ���Ԥ��ޤ��� ����������ȡ�C �롼�פε�Ǽ�ѿ����롼�פ��оݤȤʤäƤ��� �ꥹ����θġ��Υ����ƥ���Ф��륨���ꥢ���ˤʤäƤ��뤫��Ǥ��� X =begin original If any part of LIST is an array, C will get very confused if you add or remove elements within the loop body, for example with C. So don't do that. X =end original LIST �Τ����줫����ʬ������Ǥ��ä����ˡ����Ȥ��� C ��Ȥä� �롼�פ����ΤǤ������Ǥ��������ꤢ�뤤���ɲä����ꤹ��� C �����˺��𤷤Ƥ��ޤ��ޤ��� �Ǥ����餽���������Ȥ򤷤ƤϤ����ޤ��� X =begin original C probably won't do what you expect if VAR is a tied or other special variable. Don't do that either. =end original VAR �� tie ����Ƥ����ꤢ�뤤��¾���ü��ѿ��Ǥ��ä����ˤ� C �Ϥ��ʤ��Τ⤯���ߤɤ���ˤ�ư���ʤ��Ǥ��礦�� �����������Ȥ⤷�ƤϤ����ޤ��� =begin original Examples: =end original ��: for (@ary) { s/foo/bar/ } for my $elem (@elements) { $elem *= 2; } for $count (reverse(1..10), "BOOM") { print $count, "\n"; sleep(1); } for (1..15) { print "Merry Christmas\n"; } foreach $item (split(/:[\\\n:]*/, $ENV{TERMCAP})) { print "Item: $item\n"; } =begin original Here's how a C programmer might code up a particular algorithm in Perl: =end original �ʲ�����ϡ�C �ץ�����ޡ��� Perl �ǤȤ��륢�르�ꥺ��򵭽Ҥ���Ȥ��� �Ȥ��Ǥ�����������Ǥ�: for (my $i = 0; $i < @ary1; $i++) { for (my $j = 0; $j < @ary2; $j++) { if ($ary1[$i] > $ary2[$j]) { last; # can't go to outer :-( } $ary1[$i] += $ary2[$j]; } # this is where that last takes me } =begin original Whereas here's how a Perl programmer more comfortable with the idiom might do it: =end original ������Ф��ơ�������� Perl �ץ�����ޡ���Ʊ�����Ȥ����ä���Ȥ��� �Ԥ�������Ǥ�: OUTER: for my $wid (@ary1) { INNER: for my $jet (@ary2) { next OUTER if $wid > $jet; $wid += $jet; } } =begin original See how much easier this is? It's cleaner, safer, and faster. It's cleaner because it's less noisy. It's safer because if code gets added between the inner and outer loops later on, the new code won't be accidentally executed. The C explicitly iterates the other loop rather than merely terminating the inner one. And it's faster because Perl executes a C statement more rapidly than it would the equivalent C loop. =end original �ɤΤ��餤���줬��ñ�ˤʤä��褦�˸����ޤ���? ��������Τǡ������ǡ� ��®�Ǥ��� �����;�פʤ�Τ����ʤ��Τ����ΤʤΤǤ��� ����ϸ����¦�Υ롼�פȳ�¦�Υ롼�פȤδ֤˥����ɤ��ղä������Ǥ⡢ �����ְ�äƼ¹Ԥ��뤳�Ȥ��ʤ��Τǰ����ʤΤǤ��� C ����¦�Υ롼�פ�λ����ΤǤϤʤ�����¦�Υ롼�פη����֤��� �Ԥ��ޤ��� �����Ƥ���ϡ�Perl �� C ʸ�򤽤�������� C �롼�פ��� ���Ф䤯�¹Ԥ���Τǹ�®�ʤΤǤ��� =begin original Perceptive Perl hackers may have noticed that a C loop has a return value, and that this value can be captured by wrapping the loop in a C block. The reward for this discovery is this cautionary advice: The return value of a C loop is unspecified and may change without notice. Do not rely on it. =end original ƶ���ϤΤ��� Perl �ϥå����ϡ�C �롼�פ��֤��ͤ����ꡢ�����ͤ� �롼�פ� C �֥��å�����ळ�Ȥˤ�ä���ª�Ǥ��뤳�Ȥ� ���դ����⤷��ޤ��� ����ȯ�����Ф����󾩤ϡ����ηٹ�Ū�ʥ��ɥХ����Ǥ�: C �롼�פ��֤��ͤ� ̤����ǡ�ͽ��ʤ����ѹ�����뤳�Ȥ�����ޤ��� ����˰�¸���ƤϤ����ޤ��� =head2 Basic BLOCKs X (���ܥ֥��å�) =begin original A BLOCK by itself (labeled or not) is semantically equivalent to a loop that executes once. Thus you can use any of the loop control statements in it to leave or restart the block. (Note that this is I true in C, C, or contrary to popular belief C blocks, which do I count as loops.) The C block is optional. =end original �֥��å����켫�Ȥ�(��٥뤬�դ��Ƥ��褦���Ĥ��Ƥʤ�������)���٤��� �¹Ԥ����롼�פȡ�ʸˡŪ�ˤ������ʤ�ΤǤ��� ���Τ��ᡢ�֥��å�����æ�Ф��뤿���֥��å��κƥ������ȤΤ���� Ǥ�դΥ롼������ʸ��Ȥ����Ȥ��Ǥ��ޤ��� (����� C��C�� ����˰���Ū��ǧ���Ȥϰۤʤ� I<�롼�פǤϤʤ�> C �֥��å����Ф��Ƥ� I<���ǤϤʤ�> �Ȥ������Ȥ����դ��Ƥ���������) C �֥��å��Ͼ�ά���뤳�Ȥ��Ǥ��ޤ��� =begin original The BLOCK construct can be used to emulate case structures. =end original BLOCK ��¤�� case ��¤��Ԥ��Τˤ�Ȥ��ޤ��� SWITCH: { if (/^abc/) { $abc = 1; last SWITCH; } if (/^def/) { $def = 1; last SWITCH; } if (/^xyz/) { $xyz = 1; last SWITCH; } $nothing = 1; } =begin original You'll also find that C loop used to create a topicalizer and a switch: =end original ���경��ȥ����å����뤿��˻Ȥ�줿 C �롼�פ⸫�뤫�⤷��ޤ���: SWITCH: for ($var) { if (/^abc/) { $abc = 1; last SWITCH; } if (/^def/) { $def = 1; last SWITCH; } if (/^xyz/) { $xyz = 1; last SWITCH; } $nothing = 1; } =begin original Such constructs are quite frequently used, both because older versions of Perl had no official C statement, and also because the new version described immediately below remains experimental and can sometimes be confusing. =end original �Ť��С������� Perl �ˤϸ����� C ʸ���ʤ���ľ��˵��Ҥ��� �������С������Ϥޤ��¸�Ū�ǻ������𤵤��뤳�Ȥ�����Τǡ� ���Τ褦�ʹ�ʸ�ϤȤƤ�褯�Ȥ��Ƥ��ޤ��� =head2 Switch Statements (switch ʸ) X X X X X =begin original Starting from Perl 5.10.1 (well, 5.10.0, but it didn't work right), you can say =end original Perl 5.10.1 ����(���äȡ�5.10.0 ����Ǥ�����������ư���Ƥ��ޤ���Ǥ���)�� �ʲ��Τ褦�˽񤯤�: use feature "switch"; =begin original to enable an experimental switch feature. This is loosely based on an old version of a Perl 6 proposal, but it no longer resembles the Perl 6 construct. You also get the switch feature whenever you declare that your code prefers to run under a version of Perl that is 5.10 or later. For example: =end original �¸�Ū�� switch ��ǽ��ͭ���ˤ��ޤ��� ����Ϥ����ޤ��� Perl 6 ��ƤθŤ��Ǥ��ˤ��Ƥ��ޤ�������Ϥ� Perl 6 �ι�ʸ�ȶ������Ϥ���ޤ��� �����ɤ� 5.10 �ʹߤ� Perl �С������Ǽ¹Ԥ����褦����������Ȥ��⤤�ĤǤ� switch ��ǽ�������ޤ��� �㤨��: use v5.14; =begin original Under the "switch" feature, Perl gains the experimental keywords C, C, C, C, and C. Starting from Perl 5.16, one can prefix the switch keywords with C to access the feature without a C statement. The keywords C and C are analogous to C and C in other languages, so the code in the previous section could be rewritten as =end original "switch" ��ǽ�δ�Ǥϡ�Perl �ϼ¸�Ū�ʥ������ C, C, C, C, C �����ޤ��� Perl 5.16 ���顢C ʸ�ʤ��ǵ�ǽ�˥����������뤿��ˡ� switch ������ɤ� C �����֤Ǥ��ޤ��� ������� C �� C ��¾�θ���Ǥ� C ����� C �� Ʊ�ͤΤ�ΤʤΤǡ�������Υ����ɤϰʲ��Τ褦�˽�ľ���ޤ�: use v5.10.1; for ($var) { when (/^abc/) { $abc = 1 } when (/^def/) { $def = 1 } when (/^xyz/) { $xyz = 1 } default { $nothing = 1 } } =begin original The C is the non-experimental way to set a topicalizer. If you wish to use the highly experimental C, that could be written like this: =end original C �ϼ��경������ꤹ��¸�Ū�Ǥʤ���ˡ�Ǥ��� �ȤƤ�¸�Ū�� C ��Ȥ������ʤ顢�ʲ��Τ褦�˽񤱤ޤ�: use v5.10.1; given ($var) { when (/^abc/) { $abc = 1 } when (/^def/) { $def = 1 } when (/^xyz/) { $xyz = 1 } default { $nothing = 1 } } =begin original As of 5.14, that can also be written this way: =end original 5.14 ���ߡ�����ϰʲ��Τ褦�ˤ�񤱤ޤ�: use v5.14; for ($var) { $abc = 1 when /^abc/; $def = 1 when /^def/; $xyz = 1 when /^xyz/; default { $nothing = 1 } } =begin original Or if you don't care to play it safe, like this: =end original ���뤤�ϡ������ˤ��뤳�Ȥ򵤤ˤ��ʤ��ʤ顢�ʲ��Τ褦�ˤ��ޤ�: use v5.14; given ($var) { $abc = 1 when /^abc/; $def = 1 when /^def/; $xyz = 1 when /^xyz/; default { $nothing = 1 } } =begin original The arguments to C and C are in scalar context, and C assigns the C<$_> variable its topic value. =end original C �� C �ؤΰ����ϥ����饳��ƥ����Ȥǡ� C �� C<$_> �ѿ������ܤ��Ƥ����ͤ��������ޤ��� =begin original Exactly what the I argument to C does is hard to describe precisely, but in general, it tries to guess what you want done. Sometimes it is interpreted as C<< $_ ~~ I >>, and sometimes it is not. It also behaves differently when lexically enclosed by a C block than it does when dynamically enclosed by a C loop. The rules are far too difficult to understand to be described here. See L later on. =end original C �ؤ� I ���������Τ˲��򤹤뤫�����Τ˵��Ҥ���Τ� �񤷤��Ǥ���������Ū�ˤϡ����ʤ��Τ��������Ȥ��¬���褦�Ȥ��ޤ��� ����� C<< $_ ~~ I >> �Ȥ��Ʋ�ᤵ�����⤢�ꡢ�����Ǥʤ����� ����ޤ��� ����Ϥޤ���C �֥��å��ǥ쥭������˰Ϥޤ줿���ϡ�C �롼�פˤ�ä�ưŪ�˰Ϥޤ줿���Ȥϰۤʤä������񤤤򤷤ޤ��� ��§�Ϥ����ǵ��Ҥ��줿�����ڤ������򤷤ˤ�����ΤǤ��� ��Ҥ��� L �򻲾Ȥ��Ƥ��������� =begin original Due to an unfortunate bug in how C was implemented between Perl 5.10 and 5.16, under those implementations the version of C<$_> governed by C is merely a lexically scoped copy of the original, not a dynamically scoped alias to the original, as it would be if it were a C or under both the original and the current Perl 6 language specification. This bug was fixed in Perl 5.18. If you really want a lexical C<$_>, specify that explicitly, but note that C is now deprecated and will warn unless warnings have been disabled: =end original Perl 5.10 �� 5.14 �δ֤Ǥ� C �μ�����ˡ�ˤ���Թ��ʥХ��ˤ�ꡢ ���ߤμ����Ǥϡ�C �ˤ�äƴ�������� C<$_> �ϡ� C �ξ��䥪�ꥸ�ʥ�ȸ���ξ���� Perl 6 ������ͤΤ褦�� ���Τ�Τ�ưŪ�������פ���̾�ǤϤʤ���ñ�ʤ�쥭�����륹�����פΥ��ԡ��Ǥ��� ���ΥХ��� Perl 5.18 �ǽ�������ޤ����� �����˥쥭������� C<$_> ���ۤ����ʤ顢����Ū�˻��ꤷ�ޤ�����C �� ��侩�ˤʤäơ��ٹ��̵���ˤ��ʤ��¤�ٹ𤵤��褦�ˤʤä����Ȥ� ���դ��Ƥ�������: given(my $_ = EXPR) { ... } =begin original If your code still needs to run on older versions, stick to C for your topicalizer and you will be less unhappy. =end original ���ʤ��Υ����ɤ��ޤ��Ť��С������Ǥ�ư���ɬ�פ�����ʤ顢 ���경��ˤ� C ��Ȥ����Ȥ��Թ��򸺤餻�ޤ��� =head2 Goto X (goto ʸ) =begin original Although not for the faint of heart, Perl does support a C statement. There are three forms: C-LABEL, C-EXPR, and C-&NAME. A loop's LABEL is not actually a valid target for a C; it's just the name of the loop. =end original ����ʿͤΤ���Ǥʤ��ˤ�ؤ餺��Perl �� C ʸ�򥵥ݡ��Ȥ��Ƥ��ޤ��� C-LABEL��C-EXPR��C-&NAME �λ��Ĥη���������ޤ��� �롼�פΥ�٥�ϼºݤˤ� C �������ʥ������åȤǤϤʤ��� �롼�פ�̾���ˤ����ޤ��� =begin original The C-LABEL form finds the statement labeled with LABEL and resumes execution there. It may not be used to go into any construct that requires initialization, such as a subroutine or a C loop. It also can't be used to go into a construct that is optimized away. It can be used to go almost anywhere else within the dynamic scope, including out of subroutines, but it's usually better to use some other construct such as C or C. The author of Perl has never felt the need to use this form of C (in Perl, that is--C is another matter). =end original C-LABEL ������ LABEL �ǥ�٥��դ����줿ʸ�򸫤Ĥ��������������� �¹Ԥ�Ƴ����ޤ��� ����ϥ��֥롼����Ǥ���Ȥ� C �롼�פΤ褦�� �������ɬ�פȤ���褦�ʹ�¤�����ӹ��ि��˻Ȥ����ȤϤǤ��ޤ��� �ޤ�����Ŭ�������̵���ʤäƤ��ޤ��褦�ʹ�¤�����ӹ��ळ�Ȥ�Ǥ��ޤ��� ưŪ�������פ���ʳ��ΤۤȤ�ɤξ��ؤϡ����֥롼����γ���ޤ�� ��ư���뤳�Ȥ��Ǥ��ޤ�; ���������̾�� C �� C �Τ褦�� �̤Τ������Ȥä��ۤ����ɤ��Ǥ��礦�� Perl �κ�Ԥϡ�̤�����ĤƤ��η����� C ��Ȥ����Ȥ� ɬ�פ��ȴ��������ȤϤ���ޤ���(Perl �ξ��Ǥ�--C �ξ��Ϥޤ��̤��äǤ�)�� =begin original The C-EXPR form expects a label name, whose scope will be resolved dynamically. This allows for computed Cs per FORTRAN, but isn't necessarily recommended if you're optimizing for maintainability: =end original C-EXPR ������ưŪ�˲�褵��륹�����פ���äƤ����٥�̾�� ���Ԥ��Ƥ��ޤ��� ����ˤ�ä� FORTRAN �η׻��� C ���¸��Ǥ��ޤ����� ������ݼ����˽Ť����֤��ΤǤ���лȤ����Ȥϻߤ᤿�����ɤ��Ǥ��礦�� goto(("FOO", "BAR", "GLARCH")[$i]); =begin original The C-&NAME form is highly magical, and substitutes a call to the named subroutine for the currently running subroutine. This is used by C subroutines that wish to load another subroutine and then pretend that the other subroutine had been called in the first place (except that any modifications to C<@_> in the current subroutine are propagated to the other subroutine.) After the C, not even C will be able to tell that this routine was called first. =end original C-&NAME �Ϲ��٤˥ޥ�����ǡ�̾���դ����֥롼����θƤӽФ��� �����ȤǼ¹Ԥ���Ƥ��륵�֥롼������֤������ޤ��� ������̤Υ��֥롼���������ɤ��ơ��ǽ�ξ��ǸƤӽФ��줿 �̤Υ��֥롼������׵᤹�뤳�Ȥ򤷤褦�Ȥ��� C ���֥롼����ǻȤ��Ƥ��Ƥޤ� (�����ȤΥ��֥롼����ˤ����� C<@_> ���Ф����ΰʳ����ѹ��ϡ� �̤Υ��֥롼��������Ť��ޤ�)�� C �θ�ǡ�C �Ǥʤ��Ƥ⤳�Υ��֥롼���� �ǽ�˸ƤФ줿�Τ��Ȥ������Ȥ������뤳�Ȥ���Ǥ���Ǥ��礦�� =begin original In almost all cases like this, it's usually a far, far better idea to use the structured control flow mechanisms of C, C, or C instead of resorting to a C. For certain applications, the catch and throw pair of C and die() for exception processing can also be a prudent approach. =end original ���Τ褦�ʥ������ΤۤȤ�ɤ��٤Ƥξ�硢C �����ΤǤϤʤ��� C��C��C �Ȥ��ä�����ե���������Ȥ����Ȥ��� ���äȤ��ä��ɤ������ǥ��Ǥ��礦�� �����Υ��ץꥱ���������Ф��Ƥϡ�C �� die() �� catch �� throw �Υڥ��Ȥ����㳰������Ԥ�����θ����ʥ��ץ������Ȥ��� �Ȥ����Ȥ��Ǥ���Ǥ��礦�� =head2 The Ellipsis Statement X<...> X<... statement> X X X X X X X<... operator> X X (��άʸ) =begin original Beginning in Perl 5.12, Perl accepts an ellipsis, "C<...>", as a placeholder for code that you haven't implemented yet. This form of ellipsis, the unimplemented statement, should not be confused with the binary flip-flop C<...> operator. One is a statement and the other an operator. (Perl doesn't usually confuse them because usually Perl can tell whether it wants an operator or a statement, but see below for exceptions.) =end original Perl 5.12 ���顢Perl �Ϥޤ��������Ƥ��ʤ������ɤΥץ졼���ۥ���Ȥ��� ��ά "C<...>" ������դ���褦�ˤʤ�ޤ����� ���η����ξ�ά��̤����ʸ�ϡ����ե�åץե��å� C<...> �黻�Ҥ� ���𤷤ʤ��Ǥ��������� ������ʸ�ǡ��⤦�����ϱ黻�ҤǤ��� (Perl �����̺��𤷤ޤ���; �ʤ��ʤ����̤� Perl �ϱ黻�Ҥ���Ƥ��뤫 ʸ����Ƥ��뤫�������뤫��Ǥ�; �������ʲ����㳰�򻲾Ȥ��Ƥ���������) =begin original When Perl 5.12 or later encounters an ellipsis statement, it parses this without error, but if and when you should actually try to execute it, Perl throws an exception with the text C: =end original Perl 5.12 �ʹߤǾ�άʸ����������ȡ����顼�ʤ��ѡ������ޤ������ºݤ� �¹Ԥ��褦�Ȥ���ȡ�C �Ȥ����ƥ����Ȥȶ����㳰���ꤲ�ޤ�: use v5.12; sub unimplemented { ... } eval { unimplemented() }; if ($@ =~ /^Unimplemented at /) { say "I found an ellipsis!"; } =begin original You can only use the elliptical statement to stand in for a complete statement. These examples of how the ellipsis works: =end original ������ʸ��Ȥ�����ǤΤ߾�άʸ��Ȥ��ޤ��� ������Ͼ�ά���ɤΤ褦��ư��뤫����Ǥ�: use v5.12; { ... } sub foo { ... } ...; eval { ... }; sub somemeth { my $self = shift; ...; } $x = do { my $n; ...; say "Hurrah!"; $n; }; =begin original The elliptical statement cannot stand in for an expression that is part of a larger statement, since the C<...> is also the three-dot version of the flip-flop operator (see L). =end original C<...> �ϥե�åץե��åױ黻��(L ����)�� 3 ���ǤǤ� ����Τǡ���άʸ�Ϥ���礭��ʸ�ΰ����μ��Ȥ��ƤϻȤ��ޤ��� =begin original These examples of attempts to use an ellipsis are syntax errors: =end original ��ά��Ȥ����Ȥ���ʲ������ʸˡ���顼�ˤʤ�ޤ�: use v5.12; print ...; open(my $fh, ">", "/dev/passwd") or ...; if ($condition && ... ) { say "Howdy" }; =begin original There are some cases where Perl can't immediately tell the difference between an expression and a statement. For instance, the syntax for a block and an anonymous hash reference constructor look the same unless there's something in the braces to give Perl a hint. The ellipsis is a syntax error if Perl doesn't guess that the C<{ ... }> is a block. In that case, it doesn't think the C<...> is an ellipsis because it's expecting an expression instead of a statement: =end original ����ʸ�Ȥΰ㤤�򤹤��������Ǥ��ʤ���礬����ޤ��� �㤨�С��֥��å���̵̾�ϥå����ե���󥹤Υ��󥹥ȥ饯���ϡ� Perl �˥ҥ�Ȥ�Ϳ�����椫�ä����ʤ����Ʊ���˸����ޤ��� ��άʸ�� Perl �� C<{ ... }> ��֥��å���Ƚ�ǤǤ��ʤ��ä����� ʸˡ���顼�Ȥʤ�ޤ��� ���ξ�硢ʸ�ǤϤʤ����ȿ�¬����Τǡ�C<...> �Ͼ�ά�Ȥ�Ƚ�Ǥ���ޤ���: =begin original @transformed = map { ... } @input; # syntax error =end original @transformed = map { ... } @input; # ʸˡ���顼 =begin original You can use a C<;> inside your block to denote that the C<{ ... }> is a block and not a hash reference constructor. Now the ellipsis works: =end original C<{ ... }> ���֥��å��Ǥ��äơ��ϥå����ե���󥹤Υ��󥹥ȥ饯���Ǥ� �ʤ����Ȥ򼨤�����˥֥��å������ C<;> ��Ȥ��ޤ��� ����Ǿ�ά��ư��ޤ�: =begin original @transformed = map {; ... } @input; # ; disambiguates =end original @transformed = map {; ... } @input; # ; ۣ��Ǥʤ� =begin original @transformed = map { ...; } @input; # ; disambiguates =end original @transformed = map { ...; } @input; # ; ۣ��Ǥʤ� =begin original Note: Some folks colloquially refer to this bit of punctuation as a "yada-yada" or "triple-dot", but its true name is actually an ellipsis. Perl does not yet accept the Unicode version, U+2026 HORIZONTAL ELLIPSIS, as an alias for C<...>, but someday it may. =end original ����: �����οʹ֤Ϥ��ζ����������Ū�ˡ֥������פ��3 ���פȤ��� ���Ȥ��ޤ���������̾���ϼºݤˤϾ�ά�Ǥ��� Perl �Ϥޤ� Unicode �Ǥ� U+2026 HORIZONTAL ELLIPSIS �� C<...> ����̾�Ȥ��� ǧ�����ޤ��󤬡����Ĥ������ʤ뤫�⤷��ޤ��� =head2 PODs: Embedded Documentation X X (POD: �Ȥ߹��ߥɥ������) =begin original Perl has a mechanism for intermixing documentation with source code. While it's expecting the beginning of a new statement, if the compiler encounters a line that begins with an equal sign and a word, like this =end original Perl �ϡ������������ɤȥɥ�����ȤȤ򺮤��񤭤��뤿��λųݤ��� ���äƤ��ޤ��� ������ʸ�λϤޤ꤬���Ԥ���Ƥ���Ȥ��ˡ�����ѥ���� �ʲ�����Τ褦�� = ����ǻϤޤäƤ����򸫤Ĥ����: =head1 Here There Be Pods! =begin original Then that text and all remaining text up through and including a line beginning with C<=cut> will be ignored. The format of the intervening text is described in L. =end original ���Υƥ����Ȥȡ�C<=cut> �ǻϤޤ�ԤޤǤ����Ƥ�̵�뤷�ޤ��� �֤�����ƥ����Ȥν񼰤� L ����������Ƥ��ޤ��� =begin original This allows you to intermix your source code and your documentation text freely, as in =end original ����ˤ�äơ������������ɤȥɥ�����ȤȤ�ʲ��˼�����Τ褦�� ��ͳ�˺����뤳�Ȥ��Ǥ���褦�ˤʤ�ޤ��� =item snazzle($) The snazzle() function will behave in the most spectacular form that you can possibly imagine, not even excepting cybernetic pyrotechnics. =cut back to the compiler, nuff of this pod stuff! sub snazzle($) { my $thingie = shift; ......... } =begin original Note that pod translators should look at only paragraphs beginning with a pod directive (it makes parsing easier), whereas the compiler actually knows to look for pod escapes even in the middle of a paragraph. This means that the following secret stuff will be ignored by both the compiler and the translators. =end original ����ѥ���ϥѥ饰��դ������ pod ���������פ����ä��Ȥ��Ƥ⤽��� ǧ���Ǥ���Τˡ�pod �ȥ�󥹥졼���� pod �ؼ��ҤǻϤޤäƤ��� �ѥ饰��դΤߤ����ܤ��٤�(����Ϲ�ʸ���Ϥ��ñ�ˤ��뤿��Ǥ�)�� ����Ȥ������Ȥ����դ��Ʋ������� �Ĥޤꡢ�ʲ�����ˤ��� "secret stuff" �ϥ���ѥ��餫��⡢ �ȥ�󥹥졼�������̵�뤵���Ȥ������ȤǤ��� $a=3; =secret stuff warn "Neither POD nor CODE!?" =cut back print "got $a\n"; =begin original You probably shouldn't rely upon the C being podded out forever. Not all pod translators are well-behaved in this regard, and perhaps the compiler will become pickier. =end original ������� C �Τ褦�ʤ�Τ���������Ϥä�̵�뤵���Ȥ������Ȥ� ��¸���٤��ǤϤ���ޤ��� ���٤Ƥ� pod �ȥ�󥹥졼�������Τ褦�˿����񤦤櫓�ǤϤ���ޤ��󤷡� ����ѥ���Ͼ��褳���̵�뤷�ʤ��褦�ˤʤ뤫�⤷��ޤ��� =begin original One may also use pod directives to quickly comment out a section of code. =end original pod �ؼ��Ҥ򡢥����ɤΰ������ü���᤯�����ȥ����Ȥ��뤿��� �Ȥ����Ȥ�Ǥ��ޤ��� =head2 Plain Old Comments (Not!) X X X<#> X X =begin original Perl can process line directives, much like the C preprocessor. Using this, one can control Perl's idea of filenames and line numbers in error or warning messages (especially for strings that are processed with C). The syntax for this mechanism is almost the same as for most C preprocessors: it matches the regular expression =end original C �Υץ�ץ����å���Ʊ���褦�ˡ�Perl �ϹԻؼ��Ҥ�����Ǥ��ޤ��� �����Ȥ����Ȥˤ�äơ����顼��å�������ٹ��å������ˤ��� �ե�����̾����ֹ�����椹�뤳�Ȥ��Ǥ��ޤ� (�äˡ�C �ǽ��������ʸ����Τ����)�� ���λ��Ȥߤι�ʸ�ϤۤȤ�ɤ� C �Υץ�ץ����å��ȤۤȤ��Ʊ���ǡ�����ɽ��: # example: '# line 42 "new_filename.plx"' /^\# \s* line \s+ (\d+) \s* (?:\s("?)([^"]+)\g2)? \s* $/x =begin original with C<$1> being the line number for the next line, and C<$3> being the optional filename (specified with or without quotes). Note that no whitespace may precede the C<< # >>, unlike modern C preprocessors. =end original �˥ޥå�������Τ� C<$1> �����ιԤι��ֹ�Ȥʤꡢ��ά���뤳�Ȥ�Ǥ��� C<$3> ��(�������Ȥ��꤫�ʤ��ǻ��ꤵ�줿)�ե�����̾�Ȥʤ�ޤ��� �Ƕ�� C �ץ�ץ����å��Ȥϰ�äơ�C<< # >> �����˶�����֤��ʤ����Ȥ� ���դ��Ƥ��������� =begin original There is a fairly obvious gotcha included with the line directive: Debuggers and profilers will only show the last source line to appear at a particular line number in a given file. Care should be taken not to cause line number collisions in code you'd like to debug later. =end original �Իؼ��ҤˤϤ��ʤ����餫�ʵ�������ޤ�: �ǥХå��ȥץ��ե�����ϡ� Ϳ����줿�ե����������ι��ֹ���Ф��Ƹ��줿�ǿ��Υ������ԤΤߤ� ɽ�����ޤ��� ���ȤǥǥХå������������ɤǤϹ��ֹ�ξ��ͤ������ʤ��褦�����դ���٤��Ǥ��� =begin original Here are some examples that you should be able to type into your command shell: =end original ���ޥ�ɥ�����ǥ����פ��뤳�ȤΤǤ�����򤤤��Ĥ��󤲤ޤ�: % perl # line 200 "bzzzt" # the '#' on the previous line must be the first char on line die 'foo'; __END__ foo at bzzzt line 201. % perl # line 200 "bzzzt" eval qq[\n#line 2001 ""\ndie 'foo']; print $@; __END__ foo at - line 2001. % perl eval qq[\n#line 200 "foo bar"\ndie 'foo']; print $@; __END__ foo at foo bar line 200. % perl # line 345 "goop" eval "\n#line " . __LINE__ . ' "' . __FILE__ ."\"\ndie 'foo'"; print $@; __END__ foo at goop line 345. =head2 Experimental Details on given and when (given �� when �μ¸�Ū�ʾܺ�) =begin original As previously mentioned, the "switch" feature is considered highly experimental; it is subject to change with little notice. In particular, C has tricky behaviours that are expected to change to become less tricky in the future. Do not rely upon its current (mis)implementation. Before Perl 5.18, C also had tricky behaviours that you should still beware of if your code must run on older versions of Perl. =end original ���˽Ҥ٤��褦�ˡ�"switch" ��ǽ�����˼¸�Ū�Ǥ���ȹͤ����Ƥ��ޤ�; �ۤȤ���Τ餻�뤳�Ȥʤ��ѹ�����뤳�Ȥ�����ޤ��� �ä� C �ϥȥ�å����ʿ����񤤤����ꡢ������ȥ�å����� �ʤ��ʤ�褦���ѹ������ͽ��Ǥ��� ���ߤ�(��)�����˰�¸���ʤ��Ǥ��������� Perl 5.18 ������Ǥϡ�C �ˤϡ������ɤ��Ť��С������� Perl �Ǥ� ư���ʤ���Фʤ�ʤ����˵���Ĥ���٤��ȥ�å����ʿ����񤤤⤢��ޤ�: =begin original Here is a longer example of C: =end original ����Ϥ��Ĺ�� C ����Ǥ�: use feature ":5.10"; given ($foo) { when (undef) { say '$foo is undefined'; } when ("foo") { say '$foo is the string "foo"'; } when ([1,3,5,7,9]) { say '$foo is an odd digit'; continue; # Fall through } when ($_ < 100) { say '$foo is numerically less than 100'; } when (\&complicated_check) { say 'a complicated check for $foo is true'; } default { die q(I don't know what to do with $foo); } } =begin original Before Perl 5.18, C assigned the value of I to merely a lexically scoped I> (!) of C<$_>, not a dynamically scoped alias the way C does. That made it similar to =end original Perl 5.18 ������Ǥϡ�C �� I ���ͤ�ñ�˥쥭�����륹�����פ� ���� C<$_> �� I> (!) ���������ޤ�; C ������褦��ưŪ �������פ������̾�ǤϤ���ޤ��� ����ϰʲ��Ȼ��Ƥ��ޤ�: do { my $_ = EXPR; ... } =begin original except that the block was automatically broken out of by a successful C or an explicit C. Because it was only a copy, and because it was only lexically scoped, not dynamically scoped, you could not do the things with it that you are used to in a C loop. In particular, it did not work for arbitrary function calls if those functions might try to access $_. Best stick to C for that. =end original ���������֥��å��� C ���������뤫������Ū�� C �ˤ�ä� ��ưŪ���˲������Ȥ������㤤�ޤ����� ����Ϥ����Υ��ԡ��ǡ�ưŪ�������פǤϤʤ��쥭������ʥ������פ��� �����ʤ��Τǡ�C �롼�פ���ǤǤ���褦�ʤ��ȤϤǤ��ޤ���Ǥ����� �äˡ�$_ �˥����������褦�Ȥ��뤫�⤷��ʤ��ؿ��ξ�硢Ǥ�դδؿ��ƤӽФ��� �Ф��Ƥ�ư��Ƥ��ޤ���Ǥ����� ���Τ���ˤ� C �ˤ������Τ����ɤǤ��� =begin original Most of the power comes from the implicit smartmatching that can sometimes apply. Most of the time, C is treated as an implicit smartmatch of C<$_>, that is, C<$_ ~~ EXPR>. (See L for more information on smartmatching.) But when I is one of the 10 exceptional cases (or things like them) listed below, it is used directly as a boolean. =end original ���Ϥ��ΤۤȤ�ɤϻ���Ŭ�Ѥ������ۤΥ��ޡ��ȥޥå��󥰤ˤ���ΤǤ��� �ۤȤ�ɤξ�硢C �ϰ��ۤ� C<$_> �Υ��ޡ��ȥޥå��󥰡� �Ĥޤ� C<$_ ~~ EXPR> �Ȥ��ư����ޤ��� (���ޡ��ȥޥå��󥰤˴ؤ��뤵��ʤ����ˤĤ��Ƥ� L �򻲾Ȥ��Ƥ���������) ������ I ����Ҥ��� 10 ���㳰�ξ��(����ӻ����褦�ʾ��) �� ��Ĥξ�硢ľ�ܿ����ͤȤ��ƻȤ��ޤ��� =over 4 =item Z<>1. =begin original A user-defined subroutine call or a method invocation. =end original �桼����������֥롼���󤫥᥽�åɸƤӽФ��� =item Z<>2. =begin original A regular expression match in the form of C, C<$foo =~ /REGEX/>, or C<$foo =~ EXPR>. Also, a negated regular expression match in the form C, C<$foo !~ /REGEX/>, or C<$foo !~ EXPR>. =end original C, C<$foo =~ /REGEX/>, C<$foo =~ EXPR> ������ ����ɽ���ޥå��󥰡� �ޤ���C, C<$foo !~ /REGEX/>, C<$foo !~ EXPR> ������ ����ɽ���ޥå��󥰤����ꡣ =item Z<>3. =begin original A smart match that uses an explicit C<~~> operator, such as C. =end original C �Τ褦�ˡ�����Ū�� C<~~> �黻�Ҥ�Ȥ����ޡ��ȥޥå��󥰡� =item Z<>4. =begin original A boolean comparison operator such as C<$_ E 10> or C<$x eq "abc">. The relational operators that this applies to are the six numeric comparisons (C<< < >>, C<< > >>, C<< <= >>, C<< >= >>, C<< == >>, and C<< != >>), and the six string comparisons (C, C, C, C, C, and C). =end original C<$_ E 10> �� C<$x eq "abc"> �Τ褦�ʿ�������ӡ� �����Ŭ�Ѥ���ط��黻�Ҥϡ�ϻ�Ĥο������ (C<< < >>, C<< > >>, C<< <= >>, C<< >= >>, C<< == >>, C<< != >>) ����� ϻ�Ĥ�ʸ������� (C, C, C, C, C, C) �Ǥ��� =begin original B You will often have to use C<$c ~~ $_> because the default case uses C<$_ ~~ $c> , which is frequently the opposite of what you want. =end original B<����:> ���Ф��� C<$c ~~ $_> ��Ȥ�ɬ�פ����뤳�Ȥ����դ��Ƥ�������; �ʤ��ʤ�ǥե���Ȥξ��� C<$_ ~~ $c> ��Ȥ�������Ϥ��Ф��Ф��������Ȥ� �դ�����Ǥ��� =item Z<>5. =begin original At least the three builtin functions C, C, and C. We might someday add more of these later if we think of them. =end original ���ʤ��Ȥ⻰�Ĥ��Ȥ߹��ߴؿ� C, C, C�� �����ˤĤ��ƹͤ���Ȥ������Ĥ���ä��ɲä��뤫�⤷��ޤ��� =item Z<>6. =begin original A negated expression, whether C or C, or a logical exclusive-or, C<(EXPR1) xor (EXPR2)>. The bitwise versions (C<~> and C<^>) are not included. =end original ����ɽ�� C �ޤ��� C�� ��¾Ū������ C<(EXPR1) xor (EXPR2)>�� �ӥå��� (C<~> �� C<^>) �ϴޤޤ�ޤ��� =item Z<>7. =begin original A filetest operator, with exactly 4 exceptions: C<-s>, C<-M>, C<-A>, and C<-C>, as these return numerical values, not boolean ones. The C<-z> filetest operator is not included in the exception list. =end original �����ͤǤϤʤ����ͤ��֤��ͤĤ��㳰: C<-s>, C<-M>, C<-A>, C<-C> ����� �ե�����ƥ��ȱ黻�ҡ� C<-z> �ե�����ƥ��ȱ黻�Ҥ��㳰�ΰ����ˤϴޤޤ�ޤ��� =item Z<>8. =begin original The C<..> and C<...> flip-flop operators. Note that the C<...> flip-flop operator is completely different from the C<...> elliptical statement just described. =end original �ե�åץե��åױ黻�� C<..> �� C<...>�� C<...> �ե�åץե��åױ黻�Ҥ���˵��Ҥ��� C<...> ��άʸ�Ȥϴ����� �ۤʤ뤳�Ȥ����դ��Ƥ��������� =back =begin original In those 8 cases above, the value of EXPR is used directly as a boolean, so no smartmatching is done. You may think of C as a smartsmartmatch. =end original ��Ҥ�Ȭ�Ĥξ�硢EXPR ���ͤ�ľ�ܿ����ͤȤ��ƻȤ��뤿�ᡢ ���ޡ��ȥޥå��󥰤ϹԤ��ޤ��� ���ޡ��ȥޥå��󥰤Ȥ��� C ��ͤ��뤫�⤷��ޤ��� =begin original Furthermore, Perl inspects the operands of logical operators to decide whether to use smartmatching for each one by applying the above test to the operands: =end original ���ˡ�Perl �ϥ��ڥ��ɤ˾�ҤΥƥ��Ȥ�Ŭ�Ѥ��뤳�Ȥǡ����줾��� ���ޡ��ȥޥå��󥰤�Ȥ����ɤ�������ꤹ�뤿��������黻�Ҥ� ���ڥ��ɤ�Ĵ�٤ޤ�: =over 4 =item Z<>9. =begin original If EXPR is C or C, the test is applied I to both EXPR1 and EXPR2. Only if I operands also pass the test, I, will the expression be treated as boolean. Otherwise, smartmatching is used. =end original EXPR �� C �ޤ��� C �ξ�硢�ƥ��Ȥ� EXPR1 �� EXPR2 ��ξ���� I<�Ƶ�Ū> ��Ŭ�Ѥ���ޤ��� I<ξ����> ���ڥ��ɤ��ƥ��Ȥ� I<�Ƶ�Ū��> �����������ˤΤߡ����μ��� �����ͤȤ��ư����ޤ��� ����ʤ���С����ޡ��ȥޥå��󥰤��Ȥ��ޤ��� =item Z<>10. =begin original If EXPR is C, C, or C, the test is applied I to EXPR1 only (which might itself be a higher-precedence AND operator, for example, and thus subject to the previous rule), not to EXPR2. If EXPR1 is to use smartmatching, then EXPR2 also does so, no matter what EXPR2 contains. But if EXPR2 does not get to use smartmatching, then the second argument will not be either. This is quite different from the C<&&> case just described, so be careful. =end original EXPR �� C, C, or C �ξ�硢 �ƥ��Ȥ� EXPR1 (�㤨�С����⤤ͥ���̤Ǥ��� AND �黻��; ���ä� ���Ҥε�§�˽���)�Τߤ��Ф��� I<�Ƶ�Ū��> Ŭ�Ѥ���ޤ�; EXPR2 �ˤ� Ŭ�Ѥ���ޤ��� EXPR1 �����ޡ��ȥޥå��󥰤�Ȥ��ʤ顢EXPR2 �⡢�������Ƥ˴ؤ�餺 �������ޤ��� ������ EXPR2 �����ޡ��ȥޥå��󥰤�Ȥ�ʤ��ʤ顢�����ܤΰ����Ϥɤ���Ǥ� ����ޤ��� ����ϴ��˵��Ҥ��� C<&&> �ξ��ȤϤ��ʤ�ۤʤ�ޤ��Τ����դ��Ƥ��������� =back =begin original These rules are complicated, but the goal is for them to do what you want (even if you don't quite understand why they are doing it). For example: =end original �����ε�§��ʣ���Ǥ�����������ɸ�� (���Ȥ����ʤ����ʤ��������Ƥ��뤫�� ���������򤷤Ƥ��ʤ��Ƥ�) ���ʤ����¹Ԥ������̤�˼¹Ԥ��뤳�ȤǤ��� �㤨��: when (/^\d+$/ && $_ < 75) { ... } =begin original will be treated as a boolean match because the rules say both a regex match and an explicit test on C<$_> will be treated as boolean. =end original ����Ͽ����ͥޥå��󥰤Ȥ��ư����ޤ�; ��§�Ǥ�����ɽ���ޥå��󥰤� C<$_> �ؤ�����Ū�ʥƥ��ȤϤɤ���⿿���ͤȤ��ư����뤫��Ǥ��� =begin original Also: =end original �ޤ�: when ([qw(foo bar)] && /baz/) { ... } =begin original will use smartmatching because only I of the operands is a boolean: the other uses smartmatching, and that wins. =end original ����ϥ��ޡ��ȥޥå��󥰤�Ȥ��ޤ�; ���ڥ��ɤ� I<���> ������ �����ͤ�����Ǥ�: �⤦�����ϥ��ޡ��ȥޥå��󥰤�Ȥ��Τǡ������餬 ͥ�褵��ޤ��� =begin original Further: =end original �����: when ([qw(foo bar)] || /^baz/) { ... } =begin original will use smart matching (only the first operand is considered), whereas =end original ����ϥ��ޡ��ȥޥå��󥰤�Ȥ��ޤ�(�ǽ�Υ��ڥ��ɤΤߤ���θ����ޤ�); ���� when (/^baz/ || [qw(foo bar)]) { ... } =begin original will test only the regex, which causes both operands to be treated as boolean. Watch out for this one, then, because an arrayref is always a true value, which makes it effectively redundant. Not a good idea. =end original ���������ɽ���Τߤ��ƥ��Ȥ��졢ξ���Υ��ڥ��ɤϿ����ͤȤ��� �����뤳�Ȥˤʤ�ޤ��� ���ξ�硢�����ե���󥹤Ͼ�˿����ͤʤΤǡ���ΨŪ�˾�Ĺ�ˤʤ뤳�Ȥ� ���ܤ��Ƥ��������� �ɤ��ͤ��ǤϤ���ޤ��� =begin original Tautologous boolean operators are still going to be optimized away. Don't be tempted to write =end original ����Ū�ʿ����ͱ黻�ҤϺ�Ŭ������ƽ����ޤ��� �ʲ��Τ褦�˽񤳤��Ȥ��ʤ��Ǥ������� when ("foo" or "bar") { ... } =begin original This will optimize down to C<"foo">, so C<"bar"> will never be considered (even though the rules say to use a smartmatch on C<"foo">). For an alternation like this, an array ref will work, because this will instigate smartmatching: =end original ����� C<"foo"> �˺�Ŭ�������Τǡ�C<"bar"> �� (���Ȥ���§�Ǥ� C<"foo"> �� ���ޡ��ȥޥå��󥰤�Ȥ��ȤʤäƤ����Ȥ��Ƥ�) ��θ����뤳�ȤϤ���ޤ��� ���Τ褦�����ؤȤ��Ƥϡ������ե���󥹤�ư��ޤ�; ����� ���ޡ��ȥޥå��󥰤�Ȥ碌�뤫��Ǥ�: when ([qw(foo bar)] { ... } =begin original This is somewhat equivalent to the C-style switch statement's fallthrough functionality (not to be confused with I fallthrough functionality--see below), wherein the same block is used for several C statements. =end original ����Ϥ����̣ C ��������� switch ʸ�μ��ξ��ؤΰ�ư(fallthrough)��ǽ�� �����Ǥ�(I ���ξ��ؤΰ�ư��ǽ�Ⱥ�Ʊ���ʤ��Ǥ�������-- ��Ҥ��ޤ�); ʣ���� C ʸ��Ʊ���֥��å����Ȥ��ޤ��� =begin original Another useful shortcut is that, if you use a literal array or hash as the argument to C, it is turned into a reference. So C is the same as C, for example. =end original ����¾�������ʾ�ά��ˡ�Ȥ��Ƥϡ�C �ΰ����Ȥ��ƥ�ƥ�������� �ϥå����񤯤ȡ�����ϥ�ե���󥹤��Ѳ����ޤ��� ����ǡ��㤨�� C �� C ��Ʊ���Ǥ��� =begin original C behaves exactly like C, which is to say that it always matches. =end original C �����Τ� C �Τ褦�˿����񤤡���� �ޥå��󥰤��ޤ��� =head3 Breaking out (æ��) =begin original You can use the C keyword to break out of the enclosing C block. Every C block is implicitly ended with a C. =end original �Ϥޤ�Ƥ��� C �֥��å�����æ�Ф��뤿��ˡ�C ������ɤ� �Ȥ��ޤ��� ���Ƥ� C �֥��å��������ˤϰ��ۤ� C ������ޤ��� =head3 Fall-through (���ξ��ؤΰ�ư(Fall-through)) =begin original You can use the C keyword to fall through from one case to the next: =end original ��Ĥξ�狼�鼡�ذ�ư���뤿��ˤϡ�C ������ɤ��Ȥ��ޤ�: given($foo) { when (/x/) { say '$foo contains an x'; continue } when (/y/) { say '$foo contains a y' } default { say '$foo does not contain a y' } } =head3 Return value (�֤���) =begin original When a C statement is also a valid expression (for example, when it's the last statement of a block), it evaluates to: =end original C ��ͭ���ʼ��Ǥ⤢��(�㤨�Х֥��å��κǸ��ʸ�Ǥ���)��硢 �ʲ��Τ褦��ɾ������ޤ�: =over 4 =item * =begin original An empty list as soon as an explicit C is encountered. =end original ����Ū�� C ����������ľ��ʤ���ꥹ�ȡ� =item * =begin original The value of the last evaluated expression of the successful C/C clause, if there happens to be one. =end original �⤷�������Ƥ���С��������� C/C ��ǺǸ��ɾ�����줿�����͡� =item * =begin original The value of the last evaluated expression of the C block if no condition is true. =end original �ɤξ��⿿�Ǥʤ���� C �֥��å��ǺǸ��ɾ�����줿�����͡� =back =begin original In both last cases, the last expression is evaluated in the context that was applied to the C block. =end original �Ǹ����Ĥξ�硢�Ǹ�μ���Ŭ�Ѥ��줿 C �֥��å���Ŭ�Ѥ��줿 ����ƥ����Ȥ�ɾ������ޤ��� =begin original Note that, unlike C and C, failed C statements always evaluate to an empty list. =end original C �� C �Ȱۤʤꡢ���Ԥ��� C ʸ�Ͼ�˶��ꥹ�Ȥ� ɾ������ޤ��� my $price = do { given ($item) { when (["pear", "apple"]) { 1 } break when "vote"; # My vote cannot be bought 1e10 when /Mona Lisa/; "unknown"; } }; =begin original Currently, C blocks can't always be used as proper expressions. This may be addressed in a future version of Perl. =end original ���ߤΤȤ�����C �֥��å��Ͼ��Ŭ�ڤʼ��Ȥ��ƻȤ����ȤϤǤ��ޤ��� ����Ͼ���ΥС������� Perl ���н褵���Ǥ��礦�� =head3 Switching in a loop (�롼����� switch) =begin original Instead of using C, you can use a C loop. For example, here's one way to count how many times a particular string occurs in an array: =end original C ��Ȥ�����ˡ�C �롼�פ�Ȥ��ޤ��� ���Ȥ��С��ʲ���������������ʸ���󤬲��󸽤�뤫������뤿��� �ҤȤĤ���ˡ�Ǥ�: use v5.10.1; my $count = 0; for (@array) { when ("foo") { ++$count } } print "\@array contains $count copies of 'foo'\n"; =begin original Or in a more recent version: =end original ���뤤�Ϥ��Ƕ�ΥС������Ǥ�: use v5.14; my $count = 0; for (@array) { ++$count when "foo"; } print "\@array contains $count copies of 'foo'\n"; =begin original At the end of all C blocks, there is an implicit C. You can override that with an explicit C if you're interested in only the first match alone. =end original C �֥��å��������ˡ����ۤ� C ������ޤ��� �⤷�ǽ�Υޥå��󥰤����˶�̣������ʤ顢����Ū�� C �Ǥ���� ��񤭤Ǥ��ޤ��� =begin original This doesn't work if you explicitly specify a loop variable, as in C. You have to use the default variable C<$_>. =end original ����ϡ�C �Τ褦������Ū�˥롼���ѿ�����ꤷ������ ư��ޤ��� �ǥե�����ѿ� C<$_> ��Ȥ�ɬ�פ�����ޤ��� =head3 Differences from Perl 6 (Perl 6 ����ΰ㤤) =begin original The Perl 5 smartmatch and C/C constructs are not compatible with their Perl 6 analogues. The most visible difference and least important difference is that, in Perl 5, parentheses are required around the argument to C and C (except when this last one is used as a statement modifier). Parentheses in Perl 6 are always optional in a control construct such as C, C, or C; they can't be made optional in Perl 5 without a great deal of potential confusion, because Perl 5 would parse the expression =end original Perl 5 �Υ��ޡ��ȥޥå��󥰤� C/C ��ʸ�� Perl 6 �Τ�Τ� �ߴ����Ϥ���ޤ��� ��äȤ��ܤ˸����ơ���äȤ���פǤʤ��㤤�ϡ�Perl 5 �Ǥϡ�C �� C �ΰ����� (��Ԥ�ʸ�����ҤȤ��ƻȤ����������)���ä��Ǥ����� ɬ�פ�����ޤ��� Perl 6 �Ǥϡ�C, C, C �Τ褦�����湽¤�Ǥ� ���ä��Ͼ�˾�ά��ǽ�Ǥ�; Perl 5 �Ǥϡ�����Ū���纮��Ȱ��������ˤ��ʤ���Ф�����ά�Ǥ��ޤ���; �ʤ��ʤ� Perl 5 �ϰʲ��Τ褦��ɽ���ˤ�����: given $foo { ... } =begin original as though the argument to C were an element of the hash C<%foo>, interpreting the braces as hash-element syntax. =end original C �ΰ����ϥϥå��� C<%foo> �����ǤǤ��뤫�Τ褦�˥ѡ������ơ� �椫�ä���ϥå�������ʸˡ�Ȥ��Ʋ�᤹�뤫��Ǥ��� =begin original However, their are many, many other differences. For example, this works in Perl 5: =end original �������������ˤϤȤƤ�¿���Τ���¾�ΰ㤤������ޤ��� �㤨�С������ Perl 5 ��ư��ޤ�: use v5.12; my @primary = ("red", "blue", "green"); if (@primary ~~ "red") { say "primary smartmatches red"; } if ("red" ~~ @primary) { say "red smartmatches primary"; } say "that's all, folks!"; =begin original But it doesn't work at all in Perl 6. Instead, you should use the (parallelizable) C operator: =end original ����������� Perl 6 �Ǥ�����ư��ޤ��� ����ˡ�(���󲽲�ǽ��) C �黻�Ҥ�Ȥ��ޤ�: if any(@primary) eq "red" { say "primary smartmatches red"; } if "red" eq any(@primary) { say "red smartmatches primary"; } =begin original The table of smartmatches in L is not identical to that proposed by the Perl 6 specification, mainly due to differences between Perl 6's and Perl 5's data models, but also because the Perl 6 spec has changed since Perl 5 rushed into early adoption. =end original L �Υ��ޡ��ȥޥå��󥰤�ɽ�� Perl 6 ���ͤ� ��Ƥ����Ƥ����Τ�Ʊ��ǤϤ���ޤ���; ��� Perl 6 �� Perl 5 �� �ǡ�����ǥ�ΰ㤤�ˤ��ޤ�����Perl 6 �λ��ͤ� Perl 5 ������˺��Ѥ��� ����ѹ����줿����Ǥ��� =begin original In Perl 6, C will always do an implicit smartmatch with its argument, while in Perl 5 it is convenient (albeit potentially confusing) to suppress this implicit smartmatch in various rather loosely-defined situations, as roughly outlined above. (The difference is largely because Perl 5 does not have, even internally, a boolean type.) =end original Perl 6 �Ǥϡ�C �Ͼ�ˤ��ΰ������Ф�����ۤΥ��ޡ��ȥޥå��󥰤� �Ԥ��ޤ�����Perl 5 �Ǥϴ�����ޤ��˼������̤ꡢ��뤯������줿�����ˤ�äƤ� ���ۤΥ��ޡ��ȥޥå��󥰤����������ۤ�������(���Ȥ����𤵤��뤫�� �Τ�ʤ��ˤ��Ƥ�)�Ǥ��� (��ʰ㤤�ϡ�Perl 5 ������Ū�ˤ��������ͷ�������ʤ����Ȥˤ��ޤ���) =cut =begin meta Translate: KIMURA Koichi (5.005_03) Update: SHIRAKATA Kentaro (5.8.8-) Status: completed =end meta