# SOME DESCRIPTIVE TITLE # Copyright (C) YEAR Free Software Foundation, Inc. # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "POT-Creation-Date: 2026-06-05 06:34+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" # #-#-#-#-# fedora-44: perlsyn.1.pot (PACKAGE VERSION) #-#-#-#-# # # #-#-#-#-# fedora-rawhide: perlsyn.1.pot (PACKAGE VERSION) #-#-#-#-# # # #-#-#-#-# mageia-cauldron: perlsyn.1.pot (PACKAGE VERSION) #-#-#-#-# # # #-#-#-#-# opensuse-leap-16-1: perlsyn.1.pot (PACKAGE VERSION) #-#-#-#-# # # #-#-#-#-# opensuse-tumbleweed: perlsyn.1.pot (PACKAGE VERSION) #-#-#-#-# # #. #-#-#-#-# debian-trixie: perlsyn.1.pot (PACKAGE VERSION) #-#-#-#-# #. ======================================================================== #. type: IX #. #-#-#-#-# debian-unstable: perlsyn.1.pot (PACKAGE VERSION) #-#-#-#-# #. ======================================================================== #. type: IX #. #-#-#-#-# fedora-44: perlsyn.1.pot (PACKAGE VERSION) #-#-#-#-# #. Required to disable full justification in groff 1.23.0. #. ======================================================================== #. type: IX #. #-#-#-#-# fedora-rawhide: perlsyn.1.pot (PACKAGE VERSION) #-#-#-#-# #. Required to disable full justification in groff 1.23.0. #. ======================================================================== #. type: IX #. #-#-#-#-# mageia-cauldron: perlsyn.1.pot (PACKAGE VERSION) #-#-#-#-# #. Required to disable full justification in groff 1.23.0. #. ======================================================================== #. type: IX #. #-#-#-#-# opensuse-leap-16-1: perlsyn.1.pot (PACKAGE VERSION) #-#-#-#-# #. Required to disable full justification in groff 1.23.0. #. ======================================================================== #. type: IX #. #-#-#-#-# opensuse-tumbleweed: perlsyn.1.pot (PACKAGE VERSION) #-#-#-#-# #. Required to disable full justification in groff 1.23.0. #. ======================================================================== #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Title" msgstr "" # #-#-#-#-# fedora-44: perlsyn.1.pot (PACKAGE VERSION) #-#-#-#-# # # #-#-#-#-# fedora-rawhide: perlsyn.1.pot (PACKAGE VERSION) #-#-#-#-# # # #-#-#-#-# mageia-cauldron: perlsyn.1.pot (PACKAGE VERSION) #-#-#-#-# # # #-#-#-#-# opensuse-leap-16-1: perlsyn.1.pot (PACKAGE VERSION) #-#-#-#-# # # #-#-#-#-# opensuse-tumbleweed: perlsyn.1.pot (PACKAGE VERSION) #-#-#-#-# # #. #-#-#-#-# debian-trixie: perlsyn.1.pot (PACKAGE VERSION) #-#-#-#-# #. ======================================================================== #. type: IX #. #-#-#-#-# debian-unstable: perlsyn.1.pot (PACKAGE VERSION) #-#-#-#-# #. ======================================================================== #. type: IX #. #-#-#-#-# fedora-44: perlsyn.1.pot (PACKAGE VERSION) #-#-#-#-# #. Required to disable full justification in groff 1.23.0. #. ======================================================================== #. type: IX #. #-#-#-#-# fedora-rawhide: perlsyn.1.pot (PACKAGE VERSION) #-#-#-#-# #. Required to disable full justification in groff 1.23.0. #. ======================================================================== #. type: IX #. #-#-#-#-# mageia-cauldron: perlsyn.1.pot (PACKAGE VERSION) #-#-#-#-# #. Required to disable full justification in groff 1.23.0. #. ======================================================================== #. type: IX #. #-#-#-#-# opensuse-leap-16-1: perlsyn.1.pot (PACKAGE VERSION) #-#-#-#-# #. Required to disable full justification in groff 1.23.0. #. ======================================================================== #. type: IX #. #-#-#-#-# opensuse-tumbleweed: perlsyn.1.pot (PACKAGE VERSION) #-#-#-#-# #. Required to disable full justification in groff 1.23.0. #. ======================================================================== #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "PERLSYN 1" msgstr "" #. type: TH #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "PERLSYN" msgstr "" #. type: TH #: debian-trixie #, no-wrap msgid "2025-07-27" msgstr "" #. type: TH #: debian-trixie debian-unstable #, no-wrap msgid "perl v5.40.1" msgstr "" #. type: TH #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Perl Programmers Reference Guide" msgstr "" #. type: SH #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "NAME" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "perlsyn - Perl syntax: declarations, statements, comments" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Xref" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "syntax" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "DESCRIPTION" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Header" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "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." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "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." msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "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." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "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 perltrap for information about how they " "differ." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Declarations" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "declaration undef undefined uninitialized" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Subsection" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "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 (CW<\\*(C`undef\\*(C'>) until it has been assigned a " "defined value, which is anything other than CW<\\*(C`undef\\*(C'>. When " "used as a number, \\&CW<\\*(C`undef\\*(C'> is treated as CW<0>; when used as " "a string, it is treated as the empty string, CW<\"\">; 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 \\&CW<\\*(C`undef\\*(C'> as a string or a number. Well, usually. " "Boolean contexts, such as:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "\\& if ($x) {}\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "are exempt from warnings (because they care about truth rather than " "definedness). Operators such as CW<\\*(C`++\\*(C'>, CW<\\*(C`--\\*(C'>, " "CW<\\*(C`+=\\*(C'>, \\&CW<\\*(C`-=\\*(C'>, and CW<\\*(C`.=\\*(C'>, that " "operate on undefined variables such as:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& undef $x;\n" "\\& $x++;\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "are also always exempt from such warnings." msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "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 CW, \\&CW, or CW, 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." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "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 CW<\\*(C`sub name\\*(C'>, thus:" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "subroutine, declaration" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& sub myname;\n" "\\& $me = myname $0 or die \"can\\*(Aqt get myname\";\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "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 " "\\&CW<\\*(C`or\\*(C'> instead of CW<\\*(C`||\\*(C'>.) The CW<\\*(C`||" "\\*(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 " "CW<\\*(C`($)\\*(C'> to turn the subroutine into a unary operator:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& sub myname ($);\n" "\\& $me = myname $0 || die \"can\\*(Aqt get myname\";\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "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 perlsub." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Subroutines declarations can also be loaded up with the " "CW<\\*(C`require\\*(C'> statement or both loaded and imported into your " "namespace with a CW<\\*(C`use\\*(C'> statement. See perlmod for details on " "this." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "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." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Comments" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "comment #" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Text from a CW<\"#\"> character until the end of the line is a comment, and " "is ignored. Exceptions include CW<\"#\"> inside a string or regular " "expression." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Simple Statements" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "statement semicolon expression ;" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "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 CW<\\*(C`eval {}\\*(C'>, CW<\\*(C`sub {}\\*(C'>, and " "\\&CW<\\*(C`do {}\\*(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." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Statement Modifiers" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "statement modifier modifier if unless while until when foreach for" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Any simple statement may optionally be followed by a I modifier, " "just before the terminating semicolon (or block ending). The possible " "modifiers are:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& if EXPR\n" "\\& unless EXPR\n" "\\& while EXPR\n" "\\& until EXPR\n" "\\& for LIST\n" "\\& foreach LIST\n" "\\& when EXPR\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The CW<\\*(C`EXPR\\*(C'> following the modifier is referred to as the " "\"condition\". Its truth or falsehood determines how the modifier will " "behave." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "\\&CW<\\*(C`if\\*(C'> executes the statement once I and only if the " "condition is true. CW<\\*(C`unless\\*(C'> is the opposite, it executes the " "statement I the condition is true (that is, if the condition is " "false). See \"Scalar values\" in perldata for definitions of true and false." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& print \"Basset hounds got long ears\" if length $ear E= 10;\n" "\\& go_outside() and play() unless $is_raining;\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The CW modifier is an iterator: it executes the statement once " "for each item in the LIST (with CW<$_> aliased to each item in turn). There " "is no syntax to specify a C-style for loop or a lexically scoped iteration " "variable in this form." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "\\& print \"Hello $_!\\en\" for qw(world Dolly nurse);\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "\\&CW<\\*(C`while\\*(C'> repeats the statement I the condition is " "true. Postfix CW<\\*(C`while\\*(C'> has the same magic treatment of some " "kinds of condition that prefix CW<\\*(C`while\\*(C'> has. " "\\&CW<\\*(C`until\\*(C'> does the opposite, it repeats the statement " "I the condition is true (or while the condition is false):" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& # Both of these count from 0 to 10.\n" "\\& print $i++ while $i E= 10;\n" "\\& print $j++ until $j E 10;\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The CW<\\*(C`while\\*(C'> and CW<\\*(C`until\\*(C'> modifiers have the usual " "\"CW<\\*(C`while\\*(C'> loop\" semantics (conditional evaluated first), " "except when applied to a \\&CW<\\*(C`do\\*(C'>-BLOCK (or to the Perl4 " "CW<\\*(C`do\\*(C'>-SUBROUTINE statement), in which case the block executes " "once before the conditional is evaluated." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "This is so that you can write loops like:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& do {\n" "\\& $line = ESTDINE;\n" "\\& ...\n" "\\& } until !defined($line) || $line eq \".\\en\"\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "See \"do\" in perlfunc. 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 CW<\\*(C`next\\*(C'>/CW<\\*(C`redo\\*(C'>) or around it (for " "CW<\\*(C`last\\*(C'>) to do that sort of thing." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "next last redo" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "For CW<\\*(C`next\\*(C'> or CW<\\*(C`redo\\*(C'>, just double the braces:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& do {{\n" "\\& next if $x == $y;\n" "\\& # do something here\n" "\\& }} until $x++ E $z;\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "For CW<\\*(C`last\\*(C'>, you have to be more elaborate and put braces " "around it:" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "last" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& {\n" "\\& do {\n" "\\& last if $x == $y**2;\n" "\\& # do something here\n" "\\& } while $x++ E= $z;\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "If you need both CW<\\*(C`next\\*(C'> and CW<\\*(C`last\\*(C'>, you have to " "do both and also use a loop label:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& LOOP: {\n" "\\& do {{\n" "\\& next if $x == $y;\n" "\\& last LOOP if $x == $y**2;\n" "\\& # do something here\n" "\\& }} until $x++ E $z;\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "\\&B The behaviour of a CW<\\*(C`my\\*(C'>, CW<\\*(C`state\\*(C'>, or " "\\&CW<\\*(C`our\\*(C'> modified with a statement modifier conditional or " "loop construct (for example, CW<\\*(C`my $x if ...\\*(C'>) is " "\\&B. The value of the CW<\\*(C`my\\*(C'> variable may be " "CW<\\*(C`undef\\*(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." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "my" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The CW<\\*(C`when\\*(C'> modifier is an experimental feature that first " "appeared in Perl 5.14. To use it, you should include a CW<\\*(C`use " "v5.14\\*(C'> declaration. (Technically, it requires only the " "CW<\\*(C`switch\\*(C'> feature, but that aspect of it was not available " "before 5.14.) Operative only from within a CW<\\*(C`foreach\\*(C'> loop or " "a CW<\\*(C`given\\*(C'> block, it executes the statement only if the " "smartmatch \\&CW<\\*(C`$_ ~~ >\\f(CIEXPRCW<\\*(C'> is true. If the " "statement executes, it is followed by a CW<\\*(C`next\\*(C'> from inside a " "CW<\\*(C`foreach\\*(C'> and CW<\\*(C`break\\*(C'> from inside a " "CW<\\*(C`given\\*(C'>." msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "Under the current implementation, the CW<\\*(C`foreach\\*(C'> loop can be " "anywhere within the CW<\\*(C`when\\*(C'> modifier's dynamic scope, but must " "be within the CW<\\*(C`given\\*(C'> block's lexical scope. This restriction " "may be relaxed in a future release. See \"Switch Statements\" below." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Compound Statements" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "statement, compound block bracket, curly curly bracket brace { } if unless given while until foreach for continue" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "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)." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "But generally, a block is delimited by curly brackets, also known as " "braces. We will call this syntactic construct a BLOCK. Because enclosing " "braces are also the syntax for hash reference constructor expressions (see " "perlref), you may occasionally need to disambiguate by placing a " "\\&CW<\\*(C`;\\*(C'> immediately after an opening brace so that Perl " "realises the brace is the start of a block. You will more frequently need " "to disambiguate the other way, by placing a CW<\\*(C`+\\*(C'> immediately " "before an opening brace to force it to be interpreted as a hash reference " "constructor expression. It is considered good style to use these " "disambiguating mechanisms liberally, not only when Perl would otherwise " "guess incorrectly." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "The following compound statements may be used to control flow:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& if (EXPR) BLOCK\n" "\\& if (EXPR) BLOCK else BLOCK\n" "\\& if (EXPR) BLOCK elsif (EXPR) BLOCK ...\n" "\\& if (EXPR) BLOCK elsif (EXPR) BLOCK ... else BLOCK\n" "\\&\n" "\\& unless (EXPR) BLOCK\n" "\\& unless (EXPR) BLOCK else BLOCK\n" "\\& unless (EXPR) BLOCK elsif (EXPR) BLOCK ...\n" "\\& unless (EXPR) BLOCK elsif (EXPR) BLOCK ... else BLOCK\n" "\\&\n" "\\& given (EXPR) BLOCK\n" "\\&\n" "\\& LABEL while (EXPR) BLOCK\n" "\\& LABEL while (EXPR) BLOCK continue BLOCK\n" "\\&\n" "\\& LABEL until (EXPR) BLOCK\n" "\\& LABEL until (EXPR) BLOCK continue BLOCK\n" "\\&\n" "\\& LABEL for (EXPR; EXPR; EXPR) BLOCK\n" "\\& LABEL for VAR (LIST) BLOCK\n" "\\& LABEL for VAR (LIST) BLOCK continue BLOCK\n" "\\&\n" "\\& LABEL foreach (EXPR; EXPR; EXPR) BLOCK\n" "\\& LABEL foreach VAR (LIST) BLOCK\n" "\\& LABEL foreach VAR (LIST) BLOCK continue BLOCK\n" "\\&\n" "\\& LABEL BLOCK\n" "\\& LABEL BLOCK continue BLOCK\n" "\\&\n" "\\& PHASE BLOCK\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "As of Perl 5.36, you can iterate over multiple values at a time by " "specifying a list of lexicals within parentheses:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& LABEL for my (VAR, VAR) (LIST) BLOCK\n" "\\& LABEL for my (VAR, VAR) (LIST) BLOCK continue BLOCK\n" "\\& LABEL foreach my (VAR, VAR) (LIST) BLOCK\n" "\\& LABEL foreach my (VAR, VAR) (LIST) BLOCK continue BLOCK\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "If enabled by the CW<\\*(C`try\\*(C'> feature, the following may also be used" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& try BLOCK catch (VAR) BLOCK\n" "\\& try BLOCK catch (VAR) BLOCK finally BLOCK\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The experimental CW<\\*(C`given\\*(C'> statement is I; see \"Switch Statements\" below for how to do so, and the " "attendant caveats." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "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:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& if (!open(FOO)) { die \"Can\\*(Aqt open $FOO: $!\" }\n" "\\& die \"Can\\*(Aqt open $FOO: $!\" unless open(FOO);\n" "\\& open(FOO) || die \"Can\\*(Aqt open $FOO: $!\";\n" "\\& open(FOO) ? () : die \"Can\\*(Aqt open $FOO: $!\";\n" "\\& # a bit exotic, that last one\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "The CW<\\*(C`if\\*(C'> statement is straightforward. Because BLOCKs are " "always bounded by curly brackets, there is never any ambiguity about which " "\\&CW<\\*(C`if\\*(C'> an CW<\\*(C`else\\*(C'> goes with. If you use " "CW<\\*(C`unless\\*(C'> in place of CW<\\*(C`if\\*(C'>, the sense of the test " "is reversed. Like CW<\\*(C`if\\*(C'>, CW<\\*(C`unless\\*(C'> can be " "followed by CW<\\*(C`else\\*(C'>. CW<\\*(C`unless\\*(C'> can even be " "followed by one or more CW<\\*(C`elsif\\*(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." msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "The CW<\\*(C`while\\*(C'> statement executes the block as long as the " "expression is true. The CW<\\*(C`until\\*(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 CW<\\*(C`next\\*(C'>, " "CW<\\*(C`last\\*(C'>, and CW<\\*(C`redo\\*(C'>. If the LABEL is omitted, " "the loop control statement refers to the innermost enclosing loop. This may " "include dynamically searching through your call-stack at run time to find " "the LABEL. Such desperate behavior triggers a warning if you use the " "CW<\\*(C`use warnings\\*(C'> pragma or the B<-w> flag." msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "If the condition expression of a CW<\\*(C`while\\*(C'> statement is based on " "any of a group of iterative expression types then it gets some magic " "treatment. The affected iterative expression types are " "CW<\\*(C`readline\\*(C'>, the CW<\\*(C`EFILEHANDLEE\\*(C'> input " "operator, CW<\\*(C`readdir\\*(C'>, CW<\\*(C`glob\\*(C'>, the " "CW<\\*(C`EPATTERNE\\*(C'> globbing operator, and " "CW<\\*(C`each\\*(C'>. If the condition expression is one of these " "expression types, then the value yielded by the iterative operator will be " "implicitly assigned to CW<$_>. If the condition expression is one of these " "expression types or an explicit assignment of one of them to a scalar, then " "the condition actually tests for definedness of the expression's value, not " "for its regular truth value." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "If there is a CW<\\*(C`continue\\*(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 " "CW<\\*(C`next\\*(C'> statement." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "When a block is preceded by a compilation phase keyword such as " "CW<\\*(C`BEGIN\\*(C'>, \\&CW<\\*(C`END\\*(C'>, CW<\\*(C`INIT\\*(C'>, " "CW<\\*(C`CHECK\\*(C'>, or CW<\\*(C`UNITCHECK\\*(C'>, then the block will run " "only during the corresponding phase of execution. See perlmod for more " "details." msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "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 \"PL_keyword_plugin\" in perlapi " "for the mechanism. If you are using such a module, see the module's " "documentation for details of the syntax that it defines." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Loop Control" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "loop control loop, control next last redo continue" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "The CW<\\*(C`next\\*(C'> command starts the next iteration of the loop:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& LINE: while (ESTDINE) {\n" "\\& next LINE if /^#/; # discard comments\n" "\\& ...\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The CW<\\*(C`last\\*(C'> command immediately exits the loop in question. " "The \\&CW<\\*(C`continue\\*(C'> block, if any, is not executed:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& LINE: while (ESTDINE) {\n" "\\& last LINE if /^$/; # exit when done with header\n" "\\& ...\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The CW<\\*(C`redo\\*(C'> command restarts the loop block without evaluating " "the conditional again. The CW<\\*(C`continue\\*(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." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "For example, when processing a file like I. If your input " "lines might end in backslashes to indicate continuation, you want to skip " "ahead and get the next record." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& while (EE) {\n" "\\& chomp;\n" "\\& if (s/\\e\\e$//) {\n" "\\& $_ .= EE;\n" "\\& redo unless eof();\n" "\\& }\n" "\\& # now process $_\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "which is Perl shorthand for the more explicitly written version:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& LINE: while (defined($line = EARGVE)) {\n" "\\& chomp($line);\n" "\\& if ($line =~ s/\\e\\e$//) {\n" "\\& $line .= EARGVE;\n" "\\& redo LINE unless eof(); # not eof(ARGV)!\n" "\\& }\n" "\\& # now process $line\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Note that if there were a CW<\\*(C`continue\\*(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 CW<\\*(C`m?pat?\\*(C'> one-time matches:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& # inspired by :1,$g/fred/s//WILMA/\n" "\\& while (EE) {\n" "\\& m?(fred)? && s//WILMA $1 WILMA/;\n" "\\& m?(barney)? && s//BETTY $1 BETTY/;\n" "\\& m?(homer)? && s//MARGE $1 MARGE/;\n" "\\& } continue {\n" "\\& print \"$ARGV $.: $_\";\n" "\\& close ARGV if eof; # reset $.\n" "\\& reset if eof; # reset ?pat?\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "If the word CW<\\*(C`while\\*(C'> is replaced by the word " "CW<\\*(C`until\\*(C'>, the sense of the test is reversed, but the " "conditional is still tested before the first iteration." msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "Loop control statements don't work in an CW<\\*(C`if\\*(C'> or " "CW<\\*(C`unless\\*(C'>, since they aren't loops. You can double the braces " "to make them such, though." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& if (/pattern/) {{\n" "\\& last if /fred/;\n" "\\& next if /barney/; # same effect as \"last\",\n" "\\& # but doesn\\*(Aqt document as well\n" "\\& # do something here\n" "\\& }}\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "This is caused by the fact that a block by itself acts as a loop that " "executes once, see \"Basic BLOCKs\"." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The form CW<\\*(C`while/if BLOCK BLOCK\\*(C'>, available in Perl 4, is no " "longer available. Replace any occurrence of CW<\\*(C`if BLOCK\\*(C'> by " "CW<\\*(C`if (do BLOCK)\\*(C'>." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "For Loops" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "for foreach" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "Perl's C-style CW<\\*(C`for\\*(C'> loop works like the corresponding " "CW<\\*(C`while\\*(C'> loop; that means that this:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& for ($i = 1; $i E 10; $i++) {\n" "\\& ...\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "is the same as this:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& $i = 1;\n" "\\& while ($i E 10) {\n" "\\& ...\n" "\\& } continue {\n" "\\& $i++;\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "There is one minor difference: if variables are declared with " "CW<\\*(C`my\\*(C'> in the initialization section of the CW<\\*(C`for\\*(C'>, " "the lexical scope of those variables is exactly the CW<\\*(C`for\\*(C'> loop " "(the body of the loop and the control sections). To illustrate:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& my $i = \\*(Aqsamba\\*(Aq;\n" "\\& for (my $i = 1; $i E= 4; $i++) {\n" "\\& print \"$i\\en\";\n" "\\& }\n" "\\& print \"$i\\en\";\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "when executed, gives:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& 1\n" "\\& 2\n" "\\& 3\n" "\\& 4\n" "\\& samba\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "As a special case, if the test in the CW<\\*(C`for\\*(C'> loop (or the " "corresponding \\&CW<\\*(C`while\\*(C'> loop) is empty, it is treated as " "true. That is, both" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& for (;;) {\n" "\\& ...\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "and" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& while () {\n" "\\& ...\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "are treated as infinite loops." msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "Besides the normal array index looping, CW<\\*(C`for\\*(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." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "eof end-of-file end of file" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& $on_a_tty = -t STDIN && -t STDOUT;\n" "\\& sub prompt { print \"yes? \" if $on_a_tty }\n" "\\& for ( prompt(); ESTDINE; prompt() ) {\n" "\\& # do something\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The condition expression of a CW<\\*(C`for\\*(C'> loop gets the same magic " "treatment of \\&CW<\\*(C`readline\\*(C'> et al that the condition expression " "of a CW<\\*(C`while\\*(C'> loop gets." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Foreach Loops" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "The CW<\\*(C`foreach\\*(C'> loop iterates over a normal list value and sets " "the scalar variable VAR to be each element of the list in turn. If the " "variable is preceded with the keyword CW<\\*(C`my\\*(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 " "CW<\\*(C`my\\*(C'>, it uses that variable instead of the global one, but " "it's still localized to the loop. This implicit localization occurs I " "for non C-style loops." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "my local" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The CW<\\*(C`foreach\\*(C'> keyword is actually a synonym for the " "CW<\\*(C`for\\*(C'> keyword, so you can use either. If VAR is omitted, " "CW<$_> is set to each value." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "$_" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "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 " "CW<\\*(C`foreach\\*(C'> loop index variable is an implicit alias for each " "item in the list that you're looping over." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "alias" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "If any part of LIST is an array, CW<\\*(C`foreach\\*(C'> will get very " "confused if you add or remove elements within the loop body, for example " "with \\&CW<\\*(C`splice\\*(C'>. So don't do that." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "splice" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "\\&CW<\\*(C`foreach\\*(C'> probably won't do what you expect if VAR is a " "tied or other special variable. Don't do that either." msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "As of Perl 5.22, there is an experimental variant of this loop that accepts " "a variable preceded by a backslash for VAR, in which case the items in the " "LIST must be references. The backslashed variable will become an alias to " "each referenced item in the LIST, which must be of the correct type. The " "variable needn't be a scalar in this case, and the backslash may be followed " "by CW<\\*(C`my\\*(C'>. To use this form, you must enable the " "CW<\\*(C`refaliasing\\*(C'> feature via CW<\\*(C`use feature\\*(C'>. (See " "feature. See also \"Assigning to References\" in perlref.)" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "As of Perl 5.36, you can iterate over multiple values at a time. You can " "only iterate with lexical scalars as the iterator variables - unlike list " "assignment, it's not possible to use CW<\\*(C`undef\\*(C'> to signify a " "value that isn't wanted. This is a limitation of the current " "implementation, and might be changed in the future." msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "If the size of the LIST is not an exact multiple of the number of iterator " "variables, then on the last iteration the \"excess\" iterator variables are " "aliases to CW<\\*(C`undef\\*(C'>, as if the LIST had CW<\\*(C`, undef\\*(C'> " "appended as many times as needed for its length to become an exact " "multiple. This happens whether LIST is a literal LIST or an array - ie " "arrays are not extended if their size is not a multiple of the iteration " "size, consistent with iterating an array one-at-a-time. As these padding " "elements are not lvalues, attempting to modify them will fail, consistent " "with the behaviour when iterating a list with literal " "CW<\\*(C`undef\\*(C'>s. If this is not the behaviour you desire, then " "before the loop starts either explicitly extend your array to be an exact " "multiple, or explicitly throw an exception." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "Examples:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& for (@ary) { s/foo/bar/ }\n" "\\&\n" "\\& for my $elem (@elements) {\n" "\\& $elem *= 2;\n" "\\& }\n" "\\&\n" "\\& for $count (reverse(1..10), \"BOOM\") {\n" "\\& print $count, \"\\en\";\n" "\\& sleep(1);\n" "\\& }\n" "\\&\n" "\\& for (1..15) { print \"Merry Christmas\\en\"; }\n" "\\&\n" "\\& foreach $item (split(/:[\\e\\e\\en:]*/, $ENV{TERMCAP})) {\n" "\\& print \"Item: $item\\en\";\n" "\\& }\n" "\\&\n" "\\& use feature \"refaliasing\";\n" "\\& no warnings \"experimental::refaliasing\";\n" "\\& foreach \\emy %hash (@array_of_hash_references) {\n" "\\& # do something with each %hash\n" "\\& }\n" "\\&\n" "\\& foreach my ($foo, $bar, $baz) (@list) {\n" "\\& # do something three-at-a-time\n" "\\& }\n" "\\&\n" "\\& foreach my ($key, $value) (%hash) {\n" "\\& # iterate over the hash\n" "\\& # The hash is immediately copied to a flat list before the loop\n" "\\& # starts. The list contains copies of keys but aliases of values.\n" "\\& # This is the same behaviour as for $var (%hash) {...}\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "Here's how a C programmer might code up a particular algorithm in Perl:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& for (my $i = 0; $i E @ary1; $i++) {\n" "\\& for (my $j = 0; $j E @ary2; $j++) {\n" "\\& if ($ary1[$i] E $ary2[$j]) {\n" "\\& last; # can\\*(Aqt go to outer :-(\n" "\\& }\n" "\\& $ary1[$i] += $ary2[$j];\n" "\\& }\n" "\\& # this is where that last takes me\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "Whereas here's how a Perl programmer more comfortable with the idiom might " "do it:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& OUTER: for my $wid (@ary1) {\n" "\\& INNER: for my $jet (@ary2) {\n" "\\& next OUTER if $wid E $jet;\n" "\\& $wid += $jet;\n" "\\& }\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "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 CW<\\*(C`next\\*(C'> explicitly iterates the other loop " "rather than merely terminating the inner one. And it's faster because Perl " "executes a CW<\\*(C`foreach\\*(C'> statement more rapidly than it would the " "equivalent C-style CW<\\*(C`for\\*(C'> loop." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Perceptive Perl hackers may have noticed that a CW<\\*(C`for\\*(C'> loop has " "a return value, and that this value can be captured by wrapping the loop in " "a CW<\\*(C`do\\*(C'> block. The reward for this discovery is this " "cautionary advice: The return value of a CW<\\*(C`for\\*(C'> loop is " "unspecified and may change without notice. Do not rely on it." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Try Catch Exception Handling" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "try catch finally" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The CW<\\*(C`try\\*(C'>/CW<\\*(C`catch\\*(C'> syntax provides control flow " "relating to exception handling. The CW<\\*(C`try\\*(C'> keyword introduces a " "block which will be executed when it is encountered, and the " "CW<\\*(C`catch\\*(C'> block provides code to handle any exception that may " "be thrown by the first." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "This syntax must first be enabled with CW<\\*(C`use feature " "\\*(Aqtry\\*(Aq\\*(C'>." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& use feature \\*(Aqtry\\*(Aq;\n" "\\&\n" "\\& try {\n" "\\& my $x = call_a_function();\n" "\\& $x E 100 or die \"Too big\";\n" "\\& send_output($x);\n" "\\& }\n" "\\& catch ($e) {\n" "\\& warn \"Unable to output a value; $e\";\n" "\\& }\n" "\\& print \"Finished\\en\";\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Here, the body of the CW<\\*(C`catch\\*(C'> block (i.e. the " "CW<\\*(C`warn\\*(C'> statement) will be executed if the initial block " "invokes the conditional CW<\\*(C`die\\*(C'>, or if either of the functions " "it invokes throws an uncaught exception. The CW<\\*(C`catch\\*(C'> block can " "inspect the CW<$e> lexical variable in this case to see what the exception " "was. If no exception was thrown then the CW<\\*(C`catch\\*(C'> block does " "not happen. In either case, execution will then continue from the following " "statement - in this example the CW<\\*(C`print\\*(C'>." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The CW<\\*(C`catch\\*(C'> keyword must be immediately followed by a variable " "declaration in parentheses, which introduces a new variable visible to the " "body of the subsequent block. Inside the block this variable will contain " "the exception value that was thrown by the code in the CW<\\*(C`try\\*(C'> " "block. It is not necessary to use the CW<\\*(C`my\\*(C'> keyword to declare " "this variable; this is implied (similar as it is for subroutine signatures)." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Both the CW<\\*(C`try\\*(C'> and the CW<\\*(C`catch\\*(C'> blocks are " "permitted to contain control-flow expressions, such as " "CW<\\*(C`return\\*(C'>, CW<\\*(C`goto\\*(C'>, or CW<\\*(C`next\\*(C'>/" "CW<\\*(C`last\\*(C'>/CW<\\*(C`redo\\*(C'>. In all cases they behave as " "expected without warnings. In particular, a CW<\\*(C`return\\*(C'> " "expression inside the CW<\\*(C`try\\*(C'> block will make its entire " "containing function return - this is in contrast to its behaviour inside an " "CW<\\*(C`eval\\*(C'> block, where it would only make that block return." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Like other control-flow syntax, CW<\\*(C`try\\*(C'> and " "CW<\\*(C`catch\\*(C'> will yield the last evaluated value when placed as the " "final statement in a function or a CW<\\*(C`do\\*(C'> block. This permits " "the syntax to be used to create a value. In this case remember not to use " "the CW<\\*(C`return\\*(C'> expression, or that will cause the containing " "function to return." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& my $value = do {\n" "\\& try {\n" "\\& get_thing(@args);\n" "\\& }\n" "\\& catch ($e) {\n" "\\& warn \"Unable to get thing - $e\";\n" "\\& $DEFAULT_THING;\n" "\\& }\n" "\\& };\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "As with other control-flow syntax, CW<\\*(C`try\\*(C'> blocks are not " "visible to \\&CW (just as for example, CW<\\*(C`while\\*(C'> or " "CW<\\*(C`foreach\\*(C'> loops are not). Successive levels of the " "CW<\\*(C`caller\\*(C'> result can see subroutine calls and " "\\&CW<\\*(C`eval\\*(C'> blocks, because those affect the way that " "CW<\\*(C`return\\*(C'> would work. Since \\&CW<\\*(C`try\\*(C'> blocks do " "not intercept CW<\\*(C`return\\*(C'>, they are not of interest to " "\\&CW<\\*(C`caller\\*(C'>." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The CW<\\*(C`try\\*(C'> and CW<\\*(C`catch\\*(C'> blocks may optionally be " "followed by a third block introduced by the CW<\\*(C`finally\\*(C'> keyword. " "This third block is executed after the rest of the construct has finished." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& try {\n" "\\& call_a_function();\n" "\\& }\n" "\\& catch ($e) {\n" "\\& warn \"Unable to call; $e\";\n" "\\& }\n" "\\& finally {\n" "\\& print \"Finished\\en\";\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The CW<\\*(C`finally\\*(C'> block is equivalent to using a " "CW<\\*(C`defer\\*(C'> block and will be invoked in the same situations; " "whether the CW<\\*(C`try\\*(C'> block completes successfully, throws an " "exception, or transfers control elsewhere by using " "\\&CW<\\*(C`return\\*(C'>, a loop control, or CW<\\*(C`goto\\*(C'>." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Unlike the CW<\\*(C`try\\*(C'> and CW<\\*(C`catch\\*(C'> blocks, a " "CW<\\*(C`finally\\*(C'> block is not permitted to \\&CW<\\*(C`return\\*(C'>, " "CW<\\*(C`goto\\*(C'> or use any loop controls. The final expression value is " "ignored, and does not affect the return value of the containing function " "even if it is placed last in the function." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Use of this CW<\\*(C`finally\\*(C'> block syntax is currently experimental " "and will emit a warning in the CW<\\*(C`experimental::try\\*(C'> category." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Basic BLOCKs" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "block" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "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 " "CW<\\*(C`eval{}\\*(C'>, CW<\\*(C`sub{}\\*(C'>, or contrary to popular belief " "\\&CW<\\*(C`do{}\\*(C'> blocks, which do I count as loops.) The " "CW<\\*(C`continue\\*(C'> block is optional." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "The BLOCK construct can be used to emulate case structures." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& SWITCH: {\n" "\\& if (/^abc/) { $abc = 1; last SWITCH; }\n" "\\& if (/^def/) { $def = 1; last SWITCH; }\n" "\\& if (/^xyz/) { $xyz = 1; last SWITCH; }\n" "\\& $nothing = 1;\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "You'll also find that CW<\\*(C`foreach\\*(C'> loop used to create a " "topicalizer and a switch:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& SWITCH:\n" "\\& for ($var) {\n" "\\& if (/^abc/) { $abc = 1; last SWITCH; }\n" "\\& if (/^def/) { $def = 1; last SWITCH; }\n" "\\& if (/^xyz/) { $xyz = 1; last SWITCH; }\n" "\\& $nothing = 1;\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Such constructs are quite frequently used, both because older versions of " "Perl had no official CW<\\*(C`switch\\*(C'> statement, and also because the " "new version described immediately below remains experimental and can " "sometimes be confusing." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "defer blocks" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "defer" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "A block prefixed by the CW<\\*(C`defer\\*(C'> modifier provides a section of " "code which runs at a later time during scope exit." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "A CW<\\*(C`defer\\*(C'> block can appear at any point where a regular block " "or other statement is permitted. If the flow of execution reaches this " "statement, the body of the block is stored for later, but not invoked " "immediately. When the flow of control leaves the containing block for any " "reason, this stored block is executed on the way past. It provides a means " "of deferring execution until a later time. This acts similarly to syntax " "provided by some other languages, often using keywords named CW<\\*(C`try / " "finally\\*(C'>." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "This syntax is available since Perl 5.36 if enabled by the " "CW<\\*(C`defer\\*(C'> named feature, and is currently experimental. If " "experimental warnings are enabled it will emit a warning when used." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& use feature \\*(Aqdefer\\*(Aq;\n" "\\&\n" "\\& {\n" "\\& say \"This happens first\";\n" "\\& defer { say \"This happens last\"; }\n" "\\&\n" "\\& say \"And this happens inbetween\";\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "If multiple CW<\\*(C`defer\\*(C'> blocks are contained in a single scope, " "they are executed in LIFO order; the last one reached is the first one " "executed." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The code stored by the CW<\\*(C`defer\\*(C'> block will be invoked when " "control leaves its containing block due to regular fallthrough, explicit " "CW<\\*(C`return\\*(C'>, exceptions thrown by CW<\\*(C`die\\*(C'> or " "propagated by functions called by it, CW<\\*(C`goto\\*(C'>, or any of the " "loop control statements CW<\\*(C`next\\*(C'>, CW<\\*(C`last\\*(C'> or " "CW<\\*(C`redo\\*(C'>." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "If the flow of control does not reach the CW<\\*(C`defer\\*(C'> statement " "itself then its body is not stored for later execution. (This is in direct " "contrast to the code provided by an CW<\\*(C`END\\*(C'> phaser block, which " "is always enqueued by the compiler, regardless of whether execution ever " "reached the line it was given on.)" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& use feature \\*(Aqdefer\\*(Aq;\n" "\\&\n" "\\& {\n" "\\& defer { say \"This will run\"; }\n" "\\& return;\n" "\\& defer { say \"This will not\"; }\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Exceptions thrown by code inside a CW<\\*(C`defer\\*(C'> block will " "propagate to the caller in the same way as any other exception thrown by " "normal code." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "If the CW<\\*(C`defer\\*(C'> block is being executed due to a thrown " "exception and throws another one it is not specified what happens, beyond " "that the caller will definitely receive an exception." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Besides throwing an exception, a CW<\\*(C`defer\\*(C'> block is not " "permitted to otherwise alter the control flow of its surrounding code. In " "particular, it may not cause its containing function to " "CW<\\*(C`return\\*(C'>, nor may it CW<\\*(C`goto\\*(C'> a label, or control " "a containing loop using CW<\\*(C`next\\*(C'>, CW<\\*(C`last\\*(C'> or " "CW<\\*(C`redo\\*(C'>. These constructions are however, permitted entirely " "within the body of the \\&CW<\\*(C`defer\\*(C'>." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& use feature \\*(Aqdefer\\*(Aq;\n" "\\&\n" "\\& {\n" "\\& defer {\n" "\\& foreach ( 1 .. 5 ) {\n" "\\& last if $_ == 3; # this is permitted\n" "\\& }\n" "\\& }\n" "\\& }\n" "\\&\n" "\\& {\n" "\\& foreach ( 6 .. 10 ) {\n" "\\& defer {\n" "\\& last if $_ == 8; # this is not\n" "\\& }\n" "\\& }\n" "\\& }\n" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Switch Statements" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "switch case given when default" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "Starting from Perl 5.10.1 (well, 5.10.0, but it didn't work right), you can " "say" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "\\& use feature \"switch\";\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "to enable an experimental switch feature. This is loosely based on an old " "version of a Raku proposal, but it no longer resembles the Raku construct. " "You also get the switch feature whenever you declare that your code prefers " "to run under a version of Perl between 5.10 and 5.34. For example:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "\\& use v5.14;\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "Under the \"switch\" feature, Perl gains the experimental keywords " "\\&CW<\\*(C`given\\*(C'>, CW<\\*(C`when\\*(C'>, CW<\\*(C`default\\*(C'>, " "CW<\\*(C`continue\\*(C'>, and CW<\\*(C`break\\*(C'>. Starting from Perl " "5.16, one can prefix the switch keywords with CW<\\*(C`CORE::\\*(C'> to " "access the feature without a CW<\\*(C`use feature\\*(C'> statement. The " "keywords CW<\\*(C`given\\*(C'> and \\&CW<\\*(C`when\\*(C'> are analogous to " "CW<\\*(C`switch\\*(C'> and \\&CW<\\*(C`case\\*(C'> in other languages -- " "though CW<\\*(C`continue\\*(C'> is not -- so the code in the previous " "section could be rewritten as" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& use v5.10.1;\n" "\\& for ($var) {\n" "\\& when (/^abc/) { $abc = 1 }\n" "\\& when (/^def/) { $def = 1 }\n" "\\& when (/^xyz/) { $xyz = 1 }\n" "\\& default { $nothing = 1 }\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "The CW<\\*(C`foreach\\*(C'> is the non-experimental way to set a " "topicalizer. If you wish to use the highly experimental " "CW<\\*(C`given\\*(C'>, that could be written like this:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& use v5.10.1;\n" "\\& given ($var) {\n" "\\& when (/^abc/) { $abc = 1 }\n" "\\& when (/^def/) { $def = 1 }\n" "\\& when (/^xyz/) { $xyz = 1 }\n" "\\& default { $nothing = 1 }\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "As of 5.14, that can also be written this way:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& use v5.14;\n" "\\& for ($var) {\n" "\\& $abc = 1 when /^abc/;\n" "\\& $def = 1 when /^def/;\n" "\\& $xyz = 1 when /^xyz/;\n" "\\& default { $nothing = 1 }\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "Or if you don't care to play it safe, like this:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& use v5.14;\n" "\\& given ($var) {\n" "\\& $abc = 1 when /^abc/;\n" "\\& $def = 1 when /^def/;\n" "\\& $xyz = 1 when /^xyz/;\n" "\\& default { $nothing = 1 }\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The arguments to CW<\\*(C`given\\*(C'> and CW<\\*(C`when\\*(C'> are in " "scalar context, and CW<\\*(C`given\\*(C'> assigns the CW<$_> variable its " "topic value." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Exactly what the I argument to CW<\\*(C`when\\*(C'> does is hard to " "describe precisely, but in general, it tries to guess what you want done. " "Sometimes it is interpreted as CW<\\*(C`$_ ~~ >\\f(CIEXPRCW<\\*(C'>, and " "sometimes it is not. It also behaves differently when lexically enclosed by " "a CW<\\*(C`given\\*(C'> block than it does when dynamically enclosed by a " "CW<\\*(C`foreach\\*(C'> loop. The rules are far too difficult to understand " "to be described here. See \"Experimental Details on given and when\" later " "on." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Due to an unfortunate bug in how CW<\\*(C`given\\*(C'> was implemented " "between Perl 5.10 and 5.16, under those implementations the version of " "CW<$_> governed by \\&CW<\\*(C`given\\*(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 \\&CW<\\*(C`foreach\\*(C'> or under both the original " "and the current Raku language specification. This bug was fixed in Perl " "5.18 (and lexicalized CW<$_> itself was removed in Perl 5.24)." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "If your code still needs to run on older versions, stick to " "CW<\\*(C`foreach\\*(C'> for your topicalizer and you will be less unhappy." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Goto" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "goto" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "Although not for the faint of heart, Perl does support a " "CW<\\*(C`goto\\*(C'> statement. There are three forms: CW<\\*(C`goto\\*(C'>-" "LABEL, CW<\\*(C`goto\\*(C'>-EXPR, and \\&CW<\\*(C`goto\\*(C'>-&NAME. A " "loop's LABEL is not actually a valid target for a CW<\\*(C`goto\\*(C'>; it's " "just the name of the loop." msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "The CW<\\*(C`goto\\*(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 " "CW<\\*(C`foreach\\*(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 CW<\\*(C`last\\*(C'> or " "CW<\\*(C`die\\*(C'>. The author of Perl has never felt the need to use this " "form of CW<\\*(C`goto\\*(C'> (in Perl, that is--C is another matter)." msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "The CW<\\*(C`goto\\*(C'>-EXPR form expects a label name, whose scope will be " "resolved dynamically. This allows for computed CW<\\*(C`goto\\*(C'>s per " "FORTRAN, but isn't necessarily recommended if you're optimizing for " "maintainability:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "\\& goto((\"FOO\", \"BAR\", \"GLARCH\")[$i]);\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The CW<\\*(C`goto\\*(C'>-&NAME form is highly magical, and substitutes a " "call to the named subroutine for the currently running subroutine. This is " "used by \\&CW 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 CW<@_> in the current subroutine are " "propagated to the other subroutine.) After the CW<\\*(C`goto\\*(C'>, not " "even CW will be able to tell that this routine was called first." msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "In almost all cases like this, it's usually a far, far better idea to use " "the structured control flow mechanisms of CW<\\*(C`next\\*(C'>, " "CW<\\*(C`last\\*(C'>, or CW<\\*(C`redo\\*(C'> instead of resorting to a " "CW<\\*(C`goto\\*(C'>. For certain applications, the catch and throw pair of " "\\&CW<\\*(C`eval{}\\*(C'> and B for exception processing can also be " "a prudent approach." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "The Ellipsis Statement" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "... ... statement ellipsis operator elliptical statement unimplemented statement unimplemented operator yada-yada yada-yada operator ... operator whatever operator triple-dot operator" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "Beginning in Perl 5.12, Perl accepts an ellipsis, \"CW<\\*(C`...\\*(C'>\", " "as a placeholder for code that you haven't implemented yet. 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 CW<\\*(C`Unimplemented\\*(C'>:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& use v5.12;\n" "\\& sub unimplemented { ... }\n" "\\& eval { unimplemented() };\n" "\\& if ($@ =~ /^Unimplemented at /) {\n" "\\& say \"I found an ellipsis!\";\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "You can only use the elliptical statement to stand in for a complete " "statement. Syntactically, \"CW<\\*(C`...;\\*(C'>\" is a complete statement, " "but, as with other kinds of semicolon-terminated statement, the semicolon " "may be omitted if \"CW<\\*(C`...\\*(C'>\" appears immediately before a " "closing brace. These examples show how the ellipsis works:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& use v5.12;\n" "\\& { ... }\n" "\\& sub foo { ... }\n" "\\& ...;\n" "\\& eval { ... };\n" "\\& sub somemeth {\n" "\\& my $self = shift;\n" "\\& ...;\n" "\\& }\n" "\\& $x = do {\n" "\\& my $n;\n" "\\& ...;\n" "\\& say \"Hurrah!\";\n" "\\& $n;\n" "\\& };\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The elliptical statement cannot stand in for an expression that is part of a " "larger statement. These examples of attempts to use an ellipsis are syntax " "errors:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& use v5.12;\n" "\\&\n" "\\& print ...;\n" "\\& open(my $fh, \"E\", \"/dev/passwd\") or ...;\n" "\\& if ($condition && ... ) { say \"Howdy\" };\n" "\\& ... if $x E $y;\n" "\\& say \"Cromulent\" if ...;\n" "\\& $flub = 5 + ...;\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "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 CW<\\*(C`{ ... }\\*(C'> is a block. Inside " "your block, you can use a CW<\\*(C`;\\*(C'> before the ellipsis to denote " "that the \\&CW<\\*(C`{ ... }\\*(C'> is a block and not a hash reference " "constructor." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "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." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "PODs: Embedded Documentation" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "POD documentation" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "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" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "\\& =head1 Here There Be Pods!\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Then that text and all remaining text up through and including a line " "beginning with CW<\\*(C`=cut\\*(C'> will be ignored. The format of the " "intervening text is described in perlpod." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "This allows you to intermix your source code and your documentation text " "freely, as in" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& =item snazzle($)\n" "\\&\n" "\\& The snazzle() function will behave in the most spectacular\n" "\\& form that you can possibly imagine, not even excepting\n" "\\& cybernetic pyrotechnics.\n" "\\&\n" "\\& =cut back to the compiler, nuff of this pod stuff!\n" "\\&\n" "\\& sub snazzle($) {\n" "\\& my $thingie = shift;\n" "\\& .........\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "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." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& $x=3;\n" "\\& =secret stuff\n" "\\& warn \"Neither POD nor CODE!?\"\n" "\\& =cut back\n" "\\& print \"got $x\\en\";\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "You probably shouldn't rely upon the CW being podded out forever. " "Not all pod translators are well-behaved in this regard, and perhaps the " "compiler will become pickier." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "One may also use pod directives to quickly comment out a section of code." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Plain Old Comments (Not!)" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "comment line # preprocessor eval" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "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 " "CW). The syntax for this mechanism is almost the same as for most C " "preprocessors: it matches the regular expression" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& # example: \\*(Aq# line 42 \"new_filename.plx\"\\*(Aq\n" "\\& /^\\e# \\es*\n" "\\& line \\es+ (\\ed+) \\es*\n" "\\& (?:\\es(\"?)([^\"]+)\\eg2)? \\es*\n" "\\& $/x\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "with CW<$1> being the line number for the next line, and CW<$3> being the " "optional filename (specified with or without quotes). Note that no " "whitespace may precede the CW<\\*(C`#\\*(C'>, unlike modern C preprocessors." msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "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." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Here are some examples that you should be able to type into your command " "shell:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& % perl\n" "\\& # line 200 \"bzzzt\"\n" "\\& # the \\*(Aq#\\*(Aq on the previous line must be the first char on line\n" "\\& die \\*(Aqfoo\\*(Aq;\n" "\\& _\\|_END_\\|_\n" "\\& foo at bzzzt line 201.\n" "\\&\n" "\\& % perl\n" "\\& # line 200 \"bzzzt\"\n" "\\& eval qq[\\en#line 2001 \"\"\\endie \\*(Aqfoo\\*(Aq]; print $@;\n" "\\& _\\|_END_\\|_\n" "\\& foo at - line 2001.\n" "\\&\n" "\\& % perl\n" "\\& eval qq[\\en#line 200 \"foo bar\"\\endie \\*(Aqfoo\\*(Aq]; print $@;\n" "\\& _\\|_END_\\|_\n" "\\& foo at foo bar line 200.\n" "\\&\n" "\\& % perl\n" "\\& # line 345 \"goop\"\n" "\\& eval \"\\en#line \" . _\\|_LINE_\\|_ . \\*(Aq \"\\*(Aq . _\\|_FILE_\\|_ .\"\\e\"\\endie \\*(Aqfoo\\*(Aq\";\n" "\\& print $@;\n" "\\& _\\|_END_\\|_\n" "\\& foo at goop line 345.\n" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Experimental Details on given and when" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "As previously mentioned, the \"switch\" feature is considered highly " "experimental (it is also scheduled to be removed in perl 5.42.0); it is " "subject to change with little notice. In particular, " "\\&CW<\\*(C`when\\*(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, CW<\\*(C`given\\*(C'> also had " "tricky behaviours that you should still beware of if your code must run on " "older versions of Perl." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "Here is a longer example of CW<\\*(C`given\\*(C'>:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& use feature \":5.10\";\n" "\\& given ($foo) {\n" "\\& when (undef) {\n" "\\& say \\*(Aq$foo is undefined\\*(Aq;\n" "\\& }\n" "\\& when (\"foo\") {\n" "\\& say \\*(Aq$foo is the string \"foo\"\\*(Aq;\n" "\\& }\n" "\\& when ([1,3,5,7,9]) {\n" "\\& say \\*(Aq$foo is an odd digit\\*(Aq;\n" "\\& continue; # Fall through\n" "\\& }\n" "\\& when ($_ E 100) {\n" "\\& say \\*(Aq$foo is numerically less than 100\\*(Aq;\n" "\\& }\n" "\\& when (\\e&complicated_check) {\n" "\\& say \\*(Aqa complicated check for $foo is true\\*(Aq;\n" "\\& }\n" "\\& default {\n" "\\& die q(I don\\*(Aqt know what to do with $foo);\n" "\\& }\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Before Perl 5.18, CW assigned the value of I to merely a " "lexically scoped \\f(BIcopy\\fR (!) of CW<$_>, not a dynamically scoped " "alias the way CW<\\*(C`foreach\\*(C'> does. That made it similar to" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "\\& do { my $_ = EXPR; ... }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "except that the block was automatically broken out of by a successful " "\\&CW<\\*(C`when\\*(C'> or an explicit CW<\\*(C`break\\*(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 " "CW<\\*(C`foreach\\*(C'> loop. In particular, it did not work for arbitrary " "function calls if those functions might try to access CW<$_>. Best stick to " "CW<\\*(C`foreach\\*(C'> for that." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Most of the power comes from the implicit smartmatching that can sometimes " "apply. Most of the time, CW is treated as an implicit " "smartmatch of CW<$_>, that is, CW<\\*(C`$_ ~~ EXPR\\*(C'>. (See " "\"Smartmatch Operator\" in perlop 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." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "1." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Item" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "A user-defined subroutine call or a method invocation." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "2." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "A regular expression match in the form of CW<\\*(C`/REGEX/\\*(C'>, " "CW<\\*(C`$foo =~ /REGEX/\\*(C'>, or CW<\\*(C`$foo =~ EXPR\\*(C'>. Also, a " "negated regular expression match in the form CW<\\*(C`!/REGEX/\\*(C'>, " "CW<\\*(C`$foo !~ /REGEX/\\*(C'>, or CW<\\*(C`$foo !~ EXPR\\*(C'>." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "3." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "A smart match that uses an explicit CW<\\*(C`~~\\*(C'> operator, such as " "CW<\\*(C`EXPR ~~ EXPR\\*(C'>." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "\\&B You will often have to use CW<\\*(C`$c ~~ $_\\*(C'> because the " "default case uses CW<\\*(C`$_ ~~ $c\\*(C'> , which is frequently the " "opposite of what you want." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "4." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "A boolean comparison operator such as CW<\\*(C`$_ E 10\\*(C'> or " "CW<\\*(C`$x eq \"abc\"\\*(C'>. The relational operators that this applies " "to are the six numeric comparisons (CW<\\*(C`E\\*(C'>, " "CW<\\*(C`E\\*(C'>, CW<\\*(C`E=\\*(C'>, CW<\\*(C`E=\\*(C'>, " "CW<\\*(C`==\\*(C'>, and CW<\\*(C`!=\\*(C'>), and the six string comparisons " "(CW<\\*(C`lt\\*(C'>, CW<\\*(C`gt\\*(C'>, CW<\\*(C`le\\*(C'>, " "CW<\\*(C`ge\\*(C'>, CW<\\*(C`eq\\*(C'>, and CW<\\*(C`ne\\*(C'>)." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "5." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "At least the three builtin functions CW, CW, and " "\\&CW. We might someday add more of these later if we think of " "them." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "6." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "A negated expression, whether CW<\\*(C`!(EXPR)\\*(C'> or CW, or a " "logical exclusive-or, CW<\\*(C`(EXPR1) xor (EXPR2)\\*(C'>. The bitwise " "versions (CW<\\*(C`~\\*(C'> and CW<\\*(C`^\\*(C'>) are not included." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "7." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "A filetest operator, with exactly 4 exceptions: CW<\\*(C`-s\\*(C'>, " "CW<\\*(C`-M\\*(C'>, CW<\\*(C`-A\\*(C'>, and \\&CW<\\*(C`-C\\*(C'>, as these " "return numerical values, not boolean ones. The CW<\\*(C`-z\\*(C'> filetest " "operator is not included in the exception list." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "8." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The CW<\\*(C`..\\*(C'> and CW<\\*(C`...\\*(C'> flip-flop operators. Note " "that the CW<\\*(C`...\\*(C'> flip-flop operator is completely different from " "the CW<\\*(C`...\\*(C'> elliptical statement just described." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "In those 8 cases above, the value of EXPR is used directly as a boolean, so " "no smartmatching is done. You may think of CW<\\*(C`when\\*(C'> as a " "smartsmartmatch." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "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:" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "9." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "If EXPR is CW<\\*(C`EXPR1 && EXPR2\\*(C'> or CW<\\*(C`EXPR1 and " "EXPR2\\*(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." msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "10." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "If EXPR is CW<\\*(C`EXPR1 || EXPR2\\*(C'>, CW<\\*(C`EXPR1 // EXPR2\\*(C'>, " "or CW<\\*(C`EXPR1 or EXPR2\\*(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 " "CW<\\*(C`&&\\*(C'> case just described, so be careful." msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "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:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "\\& when (/^\\ed+$/ && $_ E 75) { ... }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "will be treated as a boolean match because the rules say both a regex match " "and an explicit test on CW<$_> will be treated as boolean." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "Also:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "\\& when ([qw(foo bar)] && /baz/) { ... }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "will use smartmatching because only I of the operands is a boolean: the " "other uses smartmatching, and that wins." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "Further:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "\\& when ([qw(foo bar)] || /^baz/) { ... }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "will use smart matching (only the first operand is considered), whereas" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "\\& when (/^baz/ || [qw(foo bar)]) { ... }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "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." msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "Tautologous boolean operators are still going to be optimized away. Don't " "be tempted to write" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "\\& when (\"foo\" or \"bar\") { ... }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "This will optimize down to CW<\"foo\">, so CW<\"bar\"> will never be " "considered (even though the rules say to use a smartmatch on CW<\"foo\">). " "For an alternation like this, an array ref will work, because this will " "instigate smartmatching:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "\\& when ([qw(foo bar)] { ... }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "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 " "\\&CW<\\*(C`case\\*(C'> statements." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Another useful shortcut is that, if you use a literal array or hash as the " "argument to CW<\\*(C`given\\*(C'>, it is turned into a reference. So " "CW is the same as CW, for example." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "\\&CW<\\*(C`default\\*(C'> behaves exactly like CW<\\*(C`when(1 == " "1)\\*(C'>, which is to say that it always matches." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "I" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Breaking out" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "You can use the CW<\\*(C`break\\*(C'> keyword to break out of the enclosing " "\\&CW<\\*(C`given\\*(C'> block. Every CW<\\*(C`when\\*(C'> block is " "implicitly ended with a CW<\\*(C`break\\*(C'>." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "I" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Fall-through" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "You can use the CW<\\*(C`continue\\*(C'> keyword to fall through from one " "case to the next immediate CW<\\*(C`when\\*(C'> or CW<\\*(C`default\\*(C'>:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& given($foo) {\n" "\\& when (/x/) { say \\*(Aq$foo contains an x\\*(Aq; continue }\n" "\\& when (/y/) { say \\*(Aq$foo contains a y\\*(Aq }\n" "\\& default { say \\*(Aq$foo does not contain a y\\*(Aq }\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "I" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Return value" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "When a CW<\\*(C`given\\*(C'> statement is also a valid expression (for " "example, when it's the last statement of a block), it evaluates to:" msgstr "" #. type: IP #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "\\(bu" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "An empty list as soon as an explicit CW<\\*(C`break\\*(C'> is encountered." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The value of the last evaluated expression of the successful " "\\&CW<\\*(C`when\\*(C'>/CW<\\*(C`default\\*(C'> clause, if there happens to " "be one." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The value of the last evaluated expression of the CW<\\*(C`given\\*(C'> " "block if no condition is true." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "In both last cases, the last expression is evaluated in the context that was " "applied to the CW<\\*(C`given\\*(C'> block." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Note that, unlike CW<\\*(C`if\\*(C'> and CW<\\*(C`unless\\*(C'>, failed " "CW<\\*(C`when\\*(C'> statements always evaluate to an empty list." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& my $price = do {\n" "\\& given ($item) {\n" "\\& when ([\"pear\", \"apple\"]) { 1 }\n" "\\& break when \"vote\"; # My vote cannot be bought\n" "\\& 1e10 when /Mona Lisa/;\n" "\\& \"unknown\";\n" "\\& }\n" "\\& };\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "Currently, CW<\\*(C`given\\*(C'> blocks can't always be used as proper " "expressions. This may be addressed in a future version of Perl." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "I" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Switching in a loop" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "Instead of using CW, you can use a CW loop. For " "example, here's one way to count how many times a particular string occurs " "in an array:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& use v5.10.1;\n" "\\& my $count = 0;\n" "\\& for (@array) {\n" "\\& when (\"foo\") { ++$count }\n" "\\& }\n" "\\& print \"\\e@array contains $count copies of \\*(Aqfoo\\*(Aq\\en\";\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "Or in a more recent version:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& use v5.14;\n" "\\& my $count = 0;\n" "\\& for (@array) {\n" "\\& ++$count when \"foo\";\n" "\\& }\n" "\\& print \"\\e@array contains $count copies of \\*(Aqfoo\\*(Aq\\en\";\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "At the end of all CW<\\*(C`when\\*(C'> blocks, there is an implicit " "CW<\\*(C`next\\*(C'>. You can override that with an explicit " "CW<\\*(C`last\\*(C'> if you're interested in only the first match alone." msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "This doesn't work if you explicitly specify a loop variable, as in " "CW<\\*(C`for $item (@array)\\*(C'>. You have to use the default variable " "CW<$_>." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "I" msgstr "" #. type: IX #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Differences from Raku" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "The Perl 5 smartmatch and CW<\\*(C`given\\*(C'>/CW<\\*(C`when\\*(C'> " "constructs are not compatible with their Raku analogues. The most visible " "difference and least important difference is that, in Perl 5, parentheses " "are required around the argument to CW and CW (except when " "this last one is used as a statement modifier). Parentheses in Raku are " "always optional in a control construct such as CW, CW, or " "CW; they can't be made optional in Perl 5 without a great deal of " "potential confusion, because Perl 5 would parse the expression" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& given $foo {\n" "\\& ...\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "as though the argument to CW<\\*(C`given\\*(C'> were an element of the hash " "\\&CW<%foo>, interpreting the braces as hash-element syntax." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "However, there are many, many other differences. For example, this works in " "Perl 5:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& use v5.12;\n" "\\& my @primary = (\"red\", \"blue\", \"green\");\n" "\\&\n" "\\& if (@primary ~~ \"red\") {\n" "\\& say \"primary smartmatches red\";\n" "\\& }\n" "\\&\n" "\\& if (\"red\" ~~ @primary) {\n" "\\& say \"red smartmatches primary\";\n" "\\& }\n" "\\&\n" "\\& say \"that\\*(Aqs all, folks!\";\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "But it doesn't work at all in Raku. Instead, you should use the " "(parallelizable) CW<\\*(C`any\\*(C'> operator:" msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "\\& if any(@primary) eq \"red\" {\n" "\\& say \"primary smartmatches red\";\n" "\\& }\n" "\\&\n" "\\& if \"red\" eq any(@primary) {\n" "\\& say \"red smartmatches primary\";\n" "\\& }\n" msgstr "" #. type: Plain text #: debian-trixie debian-unstable msgid "" "The table of smartmatches in \"Smartmatch Operator\" in perlop is not " "identical to that proposed by the Raku specification, mainly due to " "differences between Raku's and Perl 5's data models, but also because the " "Raku spec has changed since Perl 5 rushed into early adoption." msgstr "" #. type: Plain text #: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "In Raku, CW 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.)" msgstr "" #. type: TH #: debian-unstable #, no-wrap msgid "2025-11-16" msgstr "" #. type: TH #: fedora-44 opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "2026-03-09" msgstr "" #. type: TH #: fedora-44 opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "perl v5.42.1" msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "Many of Perl\\*(Aqs 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." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "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 (CW<\\*(C`undef\\*(C'>) until it has been assigned a " "defined value, which is anything other than CW<\\*(C`undef\\*(C'>. When " "used as a number, \\&CW<\\*(C`undef\\*(C'> is treated as CW<0>; when used as " "a string, it is treated as the empty string, CW<\"\">; and when used as a " "reference that isn\\*(Aqt being assigned to, it is treated as an error. If " "you enable warnings, you\\*(Aqll be notified of an uninitialized value " "whenever you treat \\&CW<\\*(C`undef\\*(C'> as a string or a number. Well, " "usually. Boolean contexts, such as:" msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "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\\*(Aqre using lexically-scoped " "private variables created with CW, \\&CW, or CW, " "you\\*(Aqll have to make sure your format or subroutine definition is within " "the same block scope as the B if you expect to be able to access those " "private variables." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "That now parses as you\\*(Aqd expect, but you still ought to get in the " "habit of using parentheses in that situation. For more on prototypes, see " "perlsub." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "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 CW<\\*(C`eval {}\\*(C'>, CW<\\*(C`sub {}\\*(C'>, and " "\\&CW<\\*(C`do {}\\*(C'> that I like compound statements, but " "aren\\*(Aqt--they\\*(Aqre just TERMs in an expression--and thus need an " "explicit termination when used as the last item in a statement." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "See \"do\" in perlfunc. Note also that the loop control statements " "described later will I work in this construct, because modifiers " "don\\*(Aqt take loop labels. Sorry. You can always put another block " "inside of it (for CW<\\*(C`next\\*(C'>/CW<\\*(C`redo\\*(C'>) or around it " "(for CW<\\*(C`last\\*(C'>) to do that sort of thing." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "\\&B The behaviour of a CW<\\*(C`my\\*(C'>, CW<\\*(C`state\\*(C'>, or " "\\&CW<\\*(C`our\\*(C'> modified with a statement modifier conditional or " "loop construct (for example, CW<\\*(C`my $x if ...\\*(C'>) is " "\\&B. The value of the CW<\\*(C`my\\*(C'> variable may be " "CW<\\*(C`undef\\*(C'>, any previously assigned value, or possibly anything " "else. Don\\*(Aqt rely on it. Future versions of perl might do something " "different from the version of perl you try it out on. Here be dragons." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "Under the current implementation, the CW<\\*(C`foreach\\*(C'> loop can be " "anywhere within the CW<\\*(C`when\\*(C'> modifier\\*(Aqs dynamic scope, but " "must be within the CW<\\*(C`given\\*(C'> block\\*(Aqs lexical scope. This " "restriction may be relaxed in a future release. See \"Switch Statements\" " "below." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "The CW<\\*(C`if\\*(C'> statement is straightforward. Because BLOCKs are " "always bounded by curly brackets, there is never any ambiguity about which " "\\&CW<\\*(C`if\\*(C'> an CW<\\*(C`else\\*(C'> goes with. If you use " "CW<\\*(C`unless\\*(C'> in place of CW<\\*(C`if\\*(C'>, the sense of the test " "is reversed. Like CW<\\*(C`if\\*(C'>, CW<\\*(C`unless\\*(C'> can be " "followed by CW<\\*(C`else\\*(C'>. CW<\\*(C`unless\\*(C'> can even be " "followed by one or more CW<\\*(C`elsif\\*(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\\*(Aqs going on." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "The CW<\\*(C`while\\*(C'> statement executes the block as long as the " "expression is true. The CW<\\*(C`until\\*(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 CW<\\*(C`next\\*(C'>, " "CW<\\*(C`last\\*(C'>, and CW<\\*(C`redo\\*(C'>. If the LABEL is omitted, " "the loop control statement refers to the innermost enclosing loop. This may " "include dynamically searching through your call-stack at run time to find " "the LABEL. Such desperate behavior triggers a warning if you use the " "CW<\\*(C`use warnings\\*(C'> pragma or the B<-w> flag. If more than one " "label with the same name occurs, any reference to that name refers to the " "one labelling the innermost enclosing loop." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "If the condition expression of a CW<\\*(C`while\\*(C'> statement is based on " "any of a group of iterative expression types then it gets some magic " "treatment. The affected iterative expression types are " "CW<\\*(C`readline\\*(C'>, the CW<\\*(C`EFILEHANDLEE\\*(C'> input " "operator, CW<\\*(C`readdir\\*(C'>, CW<\\*(C`glob\\*(C'>, the " "CW<\\*(C`EPATTERNE\\*(C'> globbing operator, and " "CW<\\*(C`each\\*(C'>. If the condition expression is one of these " "expression types, then the value yielded by the iterative operator will be " "implicitly assigned to CW<$_>. If the condition expression is one of these " "expression types or an explicit assignment of one of them to a scalar, then " "the condition actually tests for definedness of the expression\\*(Aqs value, " "not for its regular truth value." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "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 \"PL_keyword_plugin\" in perlapi " "for the mechanism. If you are using such a module, see the module\\*(Aqs " "documentation for details of the syntax that it defines." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "Loop control statements don\\*(Aqt work in an CW<\\*(C`if\\*(C'> or " "CW<\\*(C`unless\\*(C'>, since they aren\\*(Aqt loops. You can double the " "braces to make them such, though." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "Perl\\*(Aqs C-style CW<\\*(C`for\\*(C'> loop works like the corresponding " "CW<\\*(C`while\\*(C'> loop; that means that this:" msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "Besides the normal array index looping, CW<\\*(C`for\\*(C'> can lend itself " "to many other interesting applications. Here\\*(Aqs 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." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "The CW<\\*(C`foreach\\*(C'> loop iterates over a normal list value and sets " "the scalar variable VAR to be each element of the list in turn. If the " "variable is preceded with the keyword CW<\\*(C`my\\*(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 " "CW<\\*(C`my\\*(C'>, it uses that variable instead of the global one, but " "it\\*(Aqs still localized to the loop. This implicit localization occurs " "I for non C-style loops." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "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 " "CW<\\*(C`foreach\\*(C'> loop index variable is an implicit alias for each " "item in the list that you\\*(Aqre looping over." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "If any part of LIST is an array, CW<\\*(C`foreach\\*(C'> will get very " "confused if you add or remove elements within the loop body, for example " "with \\&CW<\\*(C`splice\\*(C'>. So don\\*(Aqt do that." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "\\&CW<\\*(C`foreach\\*(C'> probably won\\*(Aqt do what you expect if VAR is " "a tied or other special variable. Don\\*(Aqt do that either." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "As of Perl 5.22, there is an experimental variant of this loop that accepts " "a variable preceded by a backslash for VAR, in which case the items in the " "LIST must be references. The backslashed variable will become an alias to " "each referenced item in the LIST, which must be of the correct type. The " "variable needn\\*(Aqt be a scalar in this case, and the backslash may be " "followed by CW<\\*(C`my\\*(C'>. To use this form, you must enable the " "CW<\\*(C`refaliasing\\*(C'> feature via CW<\\*(C`use feature\\*(C'>. (See " "feature. See also \"Assigning to References\" in perlref.)" msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "As of Perl 5.36, you can iterate over multiple values at a time. You can " "only iterate with lexical scalars as the iterator variables - unlike list " "assignment, it\\*(Aqs not possible to use CW<\\*(C`undef\\*(C'> to signify a " "value that isn\\*(Aqt wanted. This is a limitation of the current " "implementation, and might be changed in the future." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "If the size of the LIST is not an exact multiple of the number of iterator " "variables, then on the last iteration the \"excess\" iterator variables are " "aliases to CW<\\*(C`undef\\*(C'>, as if the LIST had CW<\\*(C`, undef\\*(C'> " "appended as many times as needed for its length to become an exact " "multiple. This happens whether LIST is a literal LIST or an array - i.e. " "arrays are not extended if their size is not a multiple of the iteration " "size, consistent with iterating an array one-at-a-time. As these padding " "elements are not lvalues, attempting to modify them will fail, consistent " "with the behaviour when iterating a list with literal " "CW<\\*(C`undef\\*(C'>s. If this is not the behaviour you desire, then " "before the loop starts either explicitly extend your array to be an exact " "multiple, or explicitly throw an exception." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "Here\\*(Aqs how a C programmer might code up a particular algorithm in Perl:" msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "Whereas here\\*(Aqs how a Perl programmer more comfortable with the idiom " "might do it:" msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "See how much easier this is? It\\*(Aqs cleaner, safer, and faster. " "It\\*(Aqs cleaner because it\\*(Aqs less noisy. It\\*(Aqs safer because if " "code gets added between the inner and outer loops later on, the new code " "won\\*(Aqt be accidentally executed. The CW<\\*(C`next\\*(C'> explicitly " "iterates the other loop rather than merely terminating the inner one. And " "it\\*(Aqs faster because Perl executes a CW<\\*(C`foreach\\*(C'> statement " "more rapidly than it would the equivalent C-style CW<\\*(C`for\\*(C'> loop." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "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 " "CW<\\*(C`eval{}\\*(C'>, CW<\\*(C`sub{}\\*(C'>, or, contrary to popular " "belief, \\&CW<\\*(C`do{}\\*(C'> blocks, which do I count as loops.) " "The CW<\\*(C`continue\\*(C'> block is optional." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "You\\*(Aqll also find that CW<\\*(C`foreach\\*(C'> loop used to create a " "topicalizer and a switch:" msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "The CW<\\*(C`switch\\*(C'> feature is discouraged for new code and is " "retained for backward compatibility." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "Starting from Perl 5.10.1 (well, 5.10.0, but it didn\\*(Aqt work right), you " "can say" msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "to enable the switch feature. This is loosely based on an old version of a " "Raku proposal, but it no longer resembles the Raku construct. You also get " "the switch feature whenever you declare that your code prefers to run under " "a version of Perl between 5.10 and 5.34. For example:" msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "Under the \"switch\" feature, Perl gains the keywords " "\\&CW<\\*(C`given\\*(C'>, CW<\\*(C`when\\*(C'>, CW<\\*(C`default\\*(C'>, " "CW<\\*(C`continue\\*(C'>, and CW<\\*(C`break\\*(C'>. Starting from Perl " "5.16, one can prefix the switch keywords with CW<\\*(C`CORE::\\*(C'> to " "access the feature without a CW<\\*(C`use feature\\*(C'> statement. The " "keywords CW<\\*(C`given\\*(C'> and \\&CW<\\*(C`when\\*(C'> are analogous to " "CW<\\*(C`switch\\*(C'> and \\&CW<\\*(C`case\\*(C'> in other languages -- " "though CW<\\*(C`continue\\*(C'> is not -- so the code in the previous " "section could be rewritten as" msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "The CW<\\*(C`foreach\\*(C'> is another way to set a topicalizer. If you " "wish to use CW<\\*(C`given\\*(C'>, that could be written like this:" msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "Or if you don\\*(Aqt care to play it safe, like this:" msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "Although not for the faint of heart, Perl does support a " "CW<\\*(C`goto\\*(C'> statement. There are three forms: CW<\\*(C`goto\\*(C'>-" "LABEL, CW<\\*(C`goto\\*(C'>-EXPR, and \\&CW<\\*(C`goto\\*(C'>-&NAME. A " "loop\\*(Aqs LABEL is not actually a valid target for a CW<\\*(C`goto\\*(C'>; " "it\\*(Aqs just the name of the loop." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "The CW<\\*(C`goto\\*(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 " "CW<\\*(C`foreach\\*(C'> loop. It also can\\*(Aqt 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\\*(Aqs " "usually better to use some other construct such as CW<\\*(C`last\\*(C'> or " "CW<\\*(C`die\\*(C'>. The author of Perl has never felt the need to use this " "form of CW<\\*(C`goto\\*(C'> (in Perl, that is--C is another matter)." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "The CW<\\*(C`goto\\*(C'>-EXPR form expects a label name, whose scope will be " "resolved dynamically. This allows for computed CW<\\*(C`goto\\*(C'>s per " "FORTRAN, but isn\\*(Aqt necessarily recommended if you\\*(Aqre optimizing " "for maintainability:" msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "In almost all cases like this, it\\*(Aqs usually a far, far better idea to " "use the structured control flow mechanisms of CW<\\*(C`next\\*(C'>, " "CW<\\*(C`last\\*(C'>, or CW<\\*(C`redo\\*(C'> instead of resorting to a " "CW<\\*(C`goto\\*(C'>. For certain applications, the catch and throw pair of " "\\&CW<\\*(C`eval{}\\*(C'> and B for exception processing can also be " "a prudent approach." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "Beginning in Perl 5.12, Perl accepts an ellipsis, \"CW<\\*(C`...\\*(C'>\", " "as a placeholder for code that you haven\\*(Aqt implemented yet. 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 CW<\\*(C`Unimplemented\\*(C'>:" msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "There are some cases where Perl can\\*(Aqt 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\\*(Aqs something in the braces to give Perl a hint. The ellipsis is a " "syntax error if Perl doesn\\*(Aqt guess that the CW<\\*(C`{ ... }\\*(C'> is " "a block. Inside your block, you can use a CW<\\*(C`;\\*(C'> before the " "ellipsis to denote that the \\&CW<\\*(C`{ ... }\\*(C'> is a block and not a " "hash reference constructor." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "Perl has a mechanism for intermixing documentation with source code. While " "it\\*(Aqs expecting the beginning of a new statement, if the compiler " "encounters a line that begins with an equal sign and a word, like this" msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "You probably shouldn\\*(Aqt rely upon the CW being podded out " "forever. Not all pod translators are well-behaved in this regard, and " "perhaps the compiler will become pickier." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "Perl can process line directives, much like the C preprocessor. Using this, " "one can control Perl\\*(Aqs idea of filenames and line numbers in error or " "warning messages (especially for strings that are processed with " "CW). The syntax for this mechanism is almost the same as for most C " "preprocessors: it matches the regular expression" msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "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\\*(Aqd like to debug later." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "These rules are complicated, but the goal is for them to do what you want " "(even if you don\\*(Aqt quite understand why they are doing it). For " "example:" msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "Tautologous boolean operators are still going to be optimized away. " "Don\\*(Aqt be tempted to write" msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "This is somewhat equivalent to the C-style switch statement\\*(Aqs " "fallthrough functionality (not to be confused with I " "fallthrough functionality--see below), wherein the same block is used for " "several \\&CW<\\*(C`case\\*(C'> statements." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "When a CW<\\*(C`given\\*(C'> statement is also a valid expression (for " "example, when it\\*(Aqs the last statement of a block), it evaluates to:" msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "Currently, CW<\\*(C`given\\*(C'> blocks can\\*(Aqt always be used as proper " "expressions. This may be addressed in a future version of Perl." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "Instead of using CW, you can use a CW loop. For " "example, here\\*(Aqs one way to count how many times a particular string " "occurs in an array:" msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "At the end of all CW<\\*(C`when\\*(C'> blocks, there is an implicit " "CW<\\*(C`next\\*(C'>. You can override that with an explicit " "CW<\\*(C`last\\*(C'> if you\\*(Aqre interested in only the first match alone." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "This doesn\\*(Aqt work if you explicitly specify a loop variable, as in " "CW<\\*(C`for $item (@array)\\*(C'>. You have to use the default variable " "CW<$_>." msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "The Perl 5 smartmatch and CW<\\*(C`given\\*(C'>/CW<\\*(C`when\\*(C'> " "constructs are not compatible with their Raku analogues. The most visible " "difference and least important difference is that, in Perl 5, parentheses " "are required around the argument to CW and CW (except when " "this last one is used as a statement modifier). Parentheses in Raku are " "always optional in a control construct such as CW, CW, or " "CW; they can\\*(Aqt be made optional in Perl 5 without a great deal " "of potential confusion, because Perl 5 would parse the expression" msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "But it doesn\\*(Aqt work at all in Raku. Instead, you should use the " "(parallelizable) CW<\\*(C`any\\*(C'> operator:" msgstr "" #. type: Plain text #: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "The table of smartmatches in \"Smartmatch Operator\" in perlop is not " "identical to that proposed by the Raku specification, mainly due to " "differences between Raku\\*(Aqs and Perl 5\\*(Aqs data models, but also " "because the Raku spec has changed since Perl 5 rushed into early adoption." msgstr "" #. type: TH #: fedora-rawhide #, no-wrap msgid "2026-03-30" msgstr "" #. type: TH #: fedora-rawhide #, no-wrap msgid "perl v5.42.2" msgstr "" #. type: TH #: mageia-cauldron #, no-wrap msgid "2025-06-24" msgstr "" #. type: TH #: mageia-cauldron #, no-wrap msgid "perl v5.42.0" msgstr ""