| 1 |
# SOME DESCRIPTIVE TITLE |
| 2 |
# Copyright (C) YEAR Free Software Foundation, Inc. |
| 3 |
# This file is distributed under the same license as the PACKAGE package. |
| 4 |
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. |
| 5 |
# |
| 6 |
#, fuzzy |
| 7 |
msgid "" |
| 8 |
msgstr "" |
| 9 |
"Project-Id-Version: PACKAGE VERSION\n" |
| 10 |
"POT-Creation-Date: 2026-06-05 06:34+0200\n" |
| 11 |
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
| 12 |
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
| 13 |
"Language-Team: LANGUAGE <[email protected]>\n" |
| 14 |
"Language: \n" |
| 15 |
"MIME-Version: 1.0\n" |
| 16 |
"Content-Type: text/plain; charset=UTF-8\n" |
| 17 |
"Content-Transfer-Encoding: 8bit\n" |
| 18 |
|
| 19 |
# #-#-#-#-# fedora-44: perlref.1.pot (PACKAGE VERSION) #-#-#-#-# |
| 20 |
# |
| 21 |
# #-#-#-#-# fedora-rawhide: perlref.1.pot (PACKAGE VERSION) #-#-#-#-# |
| 22 |
# |
| 23 |
# #-#-#-#-# mageia-cauldron: perlref.1.pot (PACKAGE VERSION) #-#-#-#-# |
| 24 |
# |
| 25 |
# #-#-#-#-# opensuse-leap-16-1: perlref.1.pot (PACKAGE VERSION) #-#-#-#-# |
| 26 |
# |
| 27 |
# #-#-#-#-# opensuse-tumbleweed: perlref.1.pot (PACKAGE VERSION) #-#-#-#-# |
| 28 |
# |
| 29 |
#. #-#-#-#-# debian-trixie: perlref.1.pot (PACKAGE VERSION) #-#-#-#-# |
| 30 |
#. ======================================================================== |
| 31 |
#. type: IX |
| 32 |
#. #-#-#-#-# debian-unstable: perlref.1.pot (PACKAGE VERSION) #-#-#-#-# |
| 33 |
#. ======================================================================== |
| 34 |
#. type: IX |
| 35 |
#. #-#-#-#-# fedora-44: perlref.1.pot (PACKAGE VERSION) #-#-#-#-# |
| 36 |
#. Required to disable full justification in groff 1.23.0. |
| 37 |
#. ======================================================================== |
| 38 |
#. type: IX |
| 39 |
#. #-#-#-#-# fedora-rawhide: perlref.1.pot (PACKAGE VERSION) #-#-#-#-# |
| 40 |
#. Required to disable full justification in groff 1.23.0. |
| 41 |
#. ======================================================================== |
| 42 |
#. type: IX |
| 43 |
#. #-#-#-#-# mageia-cauldron: perlref.1.pot (PACKAGE VERSION) #-#-#-#-# |
| 44 |
#. Required to disable full justification in groff 1.23.0. |
| 45 |
#. ======================================================================== |
| 46 |
#. type: IX |
| 47 |
#. #-#-#-#-# opensuse-leap-16-1: perlref.1.pot (PACKAGE VERSION) #-#-#-#-# |
| 48 |
#. Required to disable full justification in groff 1.23.0. |
| 49 |
#. ======================================================================== |
| 50 |
#. type: IX |
| 51 |
#. #-#-#-#-# opensuse-tumbleweed: perlref.1.pot (PACKAGE VERSION) #-#-#-#-# |
| 52 |
#. Required to disable full justification in groff 1.23.0. |
| 53 |
#. ======================================================================== |
| 54 |
#. type: IX |
| 55 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 56 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 57 |
#, no-wrap |
| 58 |
msgid "Title" |
| 59 |
msgstr "" |
| 60 |
|
| 61 |
# #-#-#-#-# fedora-44: perlref.1.pot (PACKAGE VERSION) #-#-#-#-# |
| 62 |
# |
| 63 |
# #-#-#-#-# fedora-rawhide: perlref.1.pot (PACKAGE VERSION) #-#-#-#-# |
| 64 |
# |
| 65 |
# #-#-#-#-# mageia-cauldron: perlref.1.pot (PACKAGE VERSION) #-#-#-#-# |
| 66 |
# |
| 67 |
# #-#-#-#-# opensuse-leap-16-1: perlref.1.pot (PACKAGE VERSION) #-#-#-#-# |
| 68 |
# |
| 69 |
# #-#-#-#-# opensuse-tumbleweed: perlref.1.pot (PACKAGE VERSION) #-#-#-#-# |
| 70 |
# |
| 71 |
#. #-#-#-#-# debian-trixie: perlref.1.pot (PACKAGE VERSION) #-#-#-#-# |
| 72 |
#. ======================================================================== |
| 73 |
#. type: IX |
| 74 |
#. #-#-#-#-# debian-unstable: perlref.1.pot (PACKAGE VERSION) #-#-#-#-# |
| 75 |
#. ======================================================================== |
| 76 |
#. type: IX |
| 77 |
#. #-#-#-#-# fedora-44: perlref.1.pot (PACKAGE VERSION) #-#-#-#-# |
| 78 |
#. Required to disable full justification in groff 1.23.0. |
| 79 |
#. ======================================================================== |
| 80 |
#. type: IX |
| 81 |
#. #-#-#-#-# fedora-rawhide: perlref.1.pot (PACKAGE VERSION) #-#-#-#-# |
| 82 |
#. Required to disable full justification in groff 1.23.0. |
| 83 |
#. ======================================================================== |
| 84 |
#. type: IX |
| 85 |
#. #-#-#-#-# mageia-cauldron: perlref.1.pot (PACKAGE VERSION) #-#-#-#-# |
| 86 |
#. Required to disable full justification in groff 1.23.0. |
| 87 |
#. ======================================================================== |
| 88 |
#. type: IX |
| 89 |
#. #-#-#-#-# opensuse-leap-16-1: perlref.1.pot (PACKAGE VERSION) #-#-#-#-# |
| 90 |
#. Required to disable full justification in groff 1.23.0. |
| 91 |
#. ======================================================================== |
| 92 |
#. type: IX |
| 93 |
#. #-#-#-#-# opensuse-tumbleweed: perlref.1.pot (PACKAGE VERSION) #-#-#-#-# |
| 94 |
#. Required to disable full justification in groff 1.23.0. |
| 95 |
#. ======================================================================== |
| 96 |
#. type: IX |
| 97 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 98 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 99 |
#, no-wrap |
| 100 |
msgid "PERLREF 1" |
| 101 |
msgstr "" |
| 102 |
|
| 103 |
#. type: TH |
| 104 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 105 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 106 |
#, no-wrap |
| 107 |
msgid "PERLREF" |
| 108 |
msgstr "" |
| 109 |
|
| 110 |
#. type: TH |
| 111 |
#: debian-trixie |
| 112 |
#, no-wrap |
| 113 |
msgid "2025-07-27" |
| 114 |
msgstr "" |
| 115 |
|
| 116 |
#. type: TH |
| 117 |
#: debian-trixie debian-unstable |
| 118 |
#, no-wrap |
| 119 |
msgid "perl v5.40.1" |
| 120 |
msgstr "" |
| 121 |
|
| 122 |
#. type: TH |
| 123 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 124 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 125 |
#, no-wrap |
| 126 |
msgid "Perl Programmers Reference Guide" |
| 127 |
msgstr "" |
| 128 |
|
| 129 |
#. type: SH |
| 130 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 131 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 132 |
#, no-wrap |
| 133 |
msgid "NAME" |
| 134 |
msgstr "" |
| 135 |
|
| 136 |
#. type: Plain text |
| 137 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 138 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 139 |
msgid "perlref - Perl references and nested data structures" |
| 140 |
msgstr "" |
| 141 |
|
| 142 |
#. type: IX |
| 143 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 144 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 145 |
#, no-wrap |
| 146 |
msgid "Xref" |
| 147 |
msgstr "" |
| 148 |
|
| 149 |
#. type: IX |
| 150 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 151 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 152 |
#, no-wrap |
| 153 |
msgid "reference pointer data structure structure struct" |
| 154 |
msgstr "" |
| 155 |
|
| 156 |
#. type: IX |
| 157 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 158 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 159 |
#, no-wrap |
| 160 |
msgid "NOTE" |
| 161 |
msgstr "" |
| 162 |
|
| 163 |
#. type: IX |
| 164 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 165 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 166 |
#, no-wrap |
| 167 |
msgid "Header" |
| 168 |
msgstr "" |
| 169 |
|
| 170 |
#. type: Plain text |
| 171 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 172 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 173 |
msgid "" |
| 174 |
"This is complete documentation about all aspects of references. For a " |
| 175 |
"shorter, tutorial introduction to just the essential features, see " |
| 176 |
"perlreftut." |
| 177 |
msgstr "" |
| 178 |
|
| 179 |
#. type: IX |
| 180 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 181 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 182 |
#, no-wrap |
| 183 |
msgid "DESCRIPTION" |
| 184 |
msgstr "" |
| 185 |
|
| 186 |
#. type: Plain text |
| 187 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 188 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 189 |
msgid "" |
| 190 |
"Before release 5 of Perl it was difficult to represent complex data " |
| 191 |
"structures, because all references had to be symbolic--and even then it was " |
| 192 |
"difficult to refer to a variable instead of a symbol table entry. Perl now " |
| 193 |
"not only makes it easier to use symbolic references to variables, but also " |
| 194 |
"lets you have \"hard\" references to any piece of data or code. Any scalar " |
| 195 |
"may hold a hard reference. Because arrays and hashes contain scalars, you " |
| 196 |
"can now easily build arrays of arrays, arrays of hashes, hashes of arrays, " |
| 197 |
"arrays of hashes of functions, and so on." |
| 198 |
msgstr "" |
| 199 |
|
| 200 |
#. type: Plain text |
| 201 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 202 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 203 |
msgid "" |
| 204 |
"Hard references are smart--they keep track of reference counts for you, " |
| 205 |
"automatically freeing the thing referred to when its reference count goes to " |
| 206 |
"zero. (Reference counts for values in self-referential or cyclic data " |
| 207 |
"structures may not go to zero without a little help; see \"Circular " |
| 208 |
"References\" for a detailed explanation.) If that thing happens to be an " |
| 209 |
"object, the object is destructed. See perlobj for more about objects. (In " |
| 210 |
"a sense, everything in Perl is an object, but we usually reserve the word " |
| 211 |
"for references to objects that have been officially \"blessed\" into a class " |
| 212 |
"package.)" |
| 213 |
msgstr "" |
| 214 |
|
| 215 |
#. type: Plain text |
| 216 |
#: debian-trixie debian-unstable |
| 217 |
msgid "" |
| 218 |
"Symbolic references are names of variables or other objects, just as a " |
| 219 |
"symbolic link in a Unix filesystem contains merely the name of a file. The " |
| 220 |
"CW<*glob> notation is something of a symbolic reference. (Symbolic " |
| 221 |
"references are sometimes called \"soft references\", but please don't call " |
| 222 |
"them that; references are confusing enough without useless synonyms.)" |
| 223 |
msgstr "" |
| 224 |
|
| 225 |
#. type: IX |
| 226 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 227 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 228 |
#, no-wrap |
| 229 |
msgid "reference, symbolic reference, soft symbolic reference soft reference" |
| 230 |
msgstr "" |
| 231 |
|
| 232 |
#. type: Plain text |
| 233 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 234 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 235 |
msgid "" |
| 236 |
"In contrast, hard references are more like hard links in a Unix file system: " |
| 237 |
"They are used to access an underlying object without concern for what its " |
| 238 |
"(other) name is. When the word \"reference\" is used without an adjective, " |
| 239 |
"as in the following paragraph, it is usually talking about a hard reference." |
| 240 |
msgstr "" |
| 241 |
|
| 242 |
#. type: IX |
| 243 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 244 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 245 |
#, no-wrap |
| 246 |
msgid "reference, hard hard reference" |
| 247 |
msgstr "" |
| 248 |
|
| 249 |
#. type: Plain text |
| 250 |
#: debian-trixie debian-unstable |
| 251 |
msgid "" |
| 252 |
"References are easy to use in Perl. There is just one overriding principle: " |
| 253 |
"in general, Perl does no implicit referencing or dereferencing. When a " |
| 254 |
"scalar is holding a reference, it always behaves as a simple scalar. It " |
| 255 |
"doesn't magically start being an array or hash or subroutine; you have to " |
| 256 |
"tell it explicitly to do so, by dereferencing it." |
| 257 |
msgstr "" |
| 258 |
|
| 259 |
#. type: IX |
| 260 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 261 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 262 |
#, no-wrap |
| 263 |
msgid "Making References" |
| 264 |
msgstr "" |
| 265 |
|
| 266 |
#. type: IX |
| 267 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 268 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 269 |
#, no-wrap |
| 270 |
msgid "reference, creation referencing" |
| 271 |
msgstr "" |
| 272 |
|
| 273 |
#. type: IX |
| 274 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 275 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 276 |
#, no-wrap |
| 277 |
msgid "Subsection" |
| 278 |
msgstr "" |
| 279 |
|
| 280 |
#. type: Plain text |
| 281 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 282 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 283 |
msgid "References can be created in several ways." |
| 284 |
msgstr "" |
| 285 |
|
| 286 |
#. type: Plain text |
| 287 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 288 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 289 |
msgid "I<Backslash Operator>" |
| 290 |
msgstr "" |
| 291 |
|
| 292 |
#. type: IX |
| 293 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 294 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 295 |
#, no-wrap |
| 296 |
msgid "\\ backslash" |
| 297 |
msgstr "" |
| 298 |
|
| 299 |
#. type: IX |
| 300 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 301 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 302 |
#, no-wrap |
| 303 |
msgid "Backslash Operator" |
| 304 |
msgstr "" |
| 305 |
|
| 306 |
#. type: Plain text |
| 307 |
#: debian-trixie debian-unstable |
| 308 |
msgid "" |
| 309 |
"By using the backslash operator on a variable, subroutine, or value. (This " |
| 310 |
"works much like the & (address-of) operator in C.) This typically creates " |
| 311 |
"I<another> reference to a variable, because there's already a reference to " |
| 312 |
"the variable in the symbol table. But the symbol table reference might go " |
| 313 |
"away, and you'll still have the reference that the backslash returned. Here " |
| 314 |
"are some examples:" |
| 315 |
msgstr "" |
| 316 |
|
| 317 |
#. type: Plain text |
| 318 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 319 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 320 |
#, no-wrap |
| 321 |
msgid "" |
| 322 |
"\\& $scalarref = \\e$foo;\n" |
| 323 |
"\\& $arrayref = \\e@ARGV;\n" |
| 324 |
"\\& $hashref = \\e%ENV;\n" |
| 325 |
"\\& $coderef = \\e&handler;\n" |
| 326 |
"\\& $globref = \\e*foo;\n" |
| 327 |
msgstr "" |
| 328 |
|
| 329 |
#. type: Plain text |
| 330 |
#: debian-trixie debian-unstable |
| 331 |
msgid "" |
| 332 |
"It isn't possible to create a true reference to an IO handle (filehandle or " |
| 333 |
"dirhandle) using the backslash operator. The most you can get is a " |
| 334 |
"reference to a typeglob, which is actually a complete symbol table entry. " |
| 335 |
"But see the explanation of the CW<*foo{THING}> syntax below. However, you " |
| 336 |
"can still use type globs and globrefs as though they were IO handles." |
| 337 |
msgstr "" |
| 338 |
|
| 339 |
#. type: Plain text |
| 340 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 341 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 342 |
msgid "I<Square Brackets>" |
| 343 |
msgstr "" |
| 344 |
|
| 345 |
#. type: IX |
| 346 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 347 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 348 |
#, no-wrap |
| 349 |
msgid "array, anonymous [ [] square bracket bracket, square arrayref array reference reference, array" |
| 350 |
msgstr "" |
| 351 |
|
| 352 |
#. type: IX |
| 353 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 354 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 355 |
#, no-wrap |
| 356 |
msgid "Square Brackets" |
| 357 |
msgstr "" |
| 358 |
|
| 359 |
#. type: Plain text |
| 360 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 361 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 362 |
msgid "A reference to an anonymous array can be created using square brackets:" |
| 363 |
msgstr "" |
| 364 |
|
| 365 |
#. type: Plain text |
| 366 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 367 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 368 |
#, no-wrap |
| 369 |
msgid "\\& $arrayref = [1, 2, [\\*(Aqa\\*(Aq, \\*(Aqb\\*(Aq, \\*(Aqc\\*(Aq]];\n" |
| 370 |
msgstr "" |
| 371 |
|
| 372 |
#. type: Plain text |
| 373 |
#: debian-trixie debian-unstable |
| 374 |
msgid "" |
| 375 |
"Here we've created a reference to an anonymous array of three elements whose " |
| 376 |
"final element is itself a reference to another anonymous array of three " |
| 377 |
"elements. (The multidimensional syntax described later can be used to " |
| 378 |
"access this. For example, after the above, CW<\\*(C`$arrayref-E<gt>[2]" |
| 379 |
"[1]\\*(C'> would have the value \"b\".)" |
| 380 |
msgstr "" |
| 381 |
|
| 382 |
#. type: Plain text |
| 383 |
#: debian-trixie debian-unstable |
| 384 |
msgid "" |
| 385 |
"Taking a reference to an enumerated list is not the same as using square " |
| 386 |
"brackets--instead it's the same as creating a list of references!" |
| 387 |
msgstr "" |
| 388 |
|
| 389 |
#. type: Plain text |
| 390 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 391 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 392 |
#, no-wrap |
| 393 |
msgid "" |
| 394 |
"\\& @list = (\\e$x, \\e@y, \\e%z);\n" |
| 395 |
"\\& @list = \\e($x, @y, %z); # same thing!\n" |
| 396 |
msgstr "" |
| 397 |
|
| 398 |
#. type: Plain text |
| 399 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 400 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 401 |
msgid "" |
| 402 |
"As a special case, CW<\\*(C`\\e(@foo)\\*(C'> returns a list of references to " |
| 403 |
"the contents of CW<@foo>, not a reference to CW<@foo> itself. Likewise for " |
| 404 |
"CW<%foo>, except that the key references are to copies (since the keys are " |
| 405 |
"just strings rather than full-fledged scalars)." |
| 406 |
msgstr "" |
| 407 |
|
| 408 |
#. type: Plain text |
| 409 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 410 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 411 |
msgid "I<Curly Brackets>" |
| 412 |
msgstr "" |
| 413 |
|
| 414 |
#. type: IX |
| 415 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 416 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 417 |
#, no-wrap |
| 418 |
msgid "hash, anonymous { {} curly bracket bracket, curly brace hashref hash reference reference, hash" |
| 419 |
msgstr "" |
| 420 |
|
| 421 |
#. type: IX |
| 422 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 423 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 424 |
#, no-wrap |
| 425 |
msgid "Curly Brackets" |
| 426 |
msgstr "" |
| 427 |
|
| 428 |
#. type: Plain text |
| 429 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 430 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 431 |
msgid "A reference to an anonymous hash can be created using curly brackets:" |
| 432 |
msgstr "" |
| 433 |
|
| 434 |
#. type: Plain text |
| 435 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 436 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 437 |
#, no-wrap |
| 438 |
msgid "" |
| 439 |
"\\& $hashref = {\n" |
| 440 |
"\\& \\*(AqAdam\\*(Aq =E<gt> \\*(AqEve\\*(Aq,\n" |
| 441 |
"\\& \\*(AqClyde\\*(Aq =E<gt> \\*(AqBonnie\\*(Aq,\n" |
| 442 |
"\\& };\n" |
| 443 |
msgstr "" |
| 444 |
|
| 445 |
#. type: Plain text |
| 446 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 447 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 448 |
msgid "" |
| 449 |
"Anonymous hash and array composers like these can be intermixed freely to " |
| 450 |
"produce as complicated a structure as you want. The multidimensional syntax " |
| 451 |
"described below works for these too. The values above are literals, but " |
| 452 |
"variables and expressions would work just as well, because assignment " |
| 453 |
"operators in Perl (even within B<local()> or B<my()>) are executable " |
| 454 |
"statements, not compile-time declarations." |
| 455 |
msgstr "" |
| 456 |
|
| 457 |
#. type: Plain text |
| 458 |
#: debian-trixie debian-unstable |
| 459 |
msgid "" |
| 460 |
"Because curly brackets (braces) are used for several other things including " |
| 461 |
"BLOCKs, you may occasionally have to disambiguate braces at the beginning of " |
| 462 |
"a statement by putting a CW<\\*(C`+\\*(C'> or a CW<\\*(C`return\\*(C'> in " |
| 463 |
"front so that Perl realizes the opening brace isn't starting a BLOCK. The " |
| 464 |
"economy and mnemonic value of using curlies is deemed worth this occasional " |
| 465 |
"extra hassle." |
| 466 |
msgstr "" |
| 467 |
|
| 468 |
#. type: Plain text |
| 469 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 470 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 471 |
msgid "" |
| 472 |
"For example, if you wanted a function to make a new hash and return a " |
| 473 |
"reference to it, you have these options:" |
| 474 |
msgstr "" |
| 475 |
|
| 476 |
#. type: Plain text |
| 477 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 478 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 479 |
#, no-wrap |
| 480 |
msgid "" |
| 481 |
"\\& sub hashem { { @_ } } # silently wrong\n" |
| 482 |
"\\& sub hashem { +{ @_ } } # ok\n" |
| 483 |
"\\& sub hashem { return { @_ } } # ok\n" |
| 484 |
msgstr "" |
| 485 |
|
| 486 |
#. type: Plain text |
| 487 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 488 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 489 |
msgid "On the other hand, if you want the other meaning, you can do this:" |
| 490 |
msgstr "" |
| 491 |
|
| 492 |
#. type: Plain text |
| 493 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 494 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 495 |
#, no-wrap |
| 496 |
msgid "" |
| 497 |
"\\& sub showem { { @_ } } # ambiguous (currently ok,\n" |
| 498 |
"\\& # but may change)\n" |
| 499 |
"\\& sub showem { {; @_ } } # ok\n" |
| 500 |
"\\& sub showem { { return @_ } } # ok\n" |
| 501 |
msgstr "" |
| 502 |
|
| 503 |
#. type: Plain text |
| 504 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 505 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 506 |
msgid "" |
| 507 |
"The leading CW<\\*(C`+{\\*(C'> and CW<\\*(C`{;\\*(C'> always serve to " |
| 508 |
"disambiguate the expression to mean either the HASH reference, or the BLOCK." |
| 509 |
msgstr "" |
| 510 |
|
| 511 |
#. type: Plain text |
| 512 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 513 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 514 |
msgid "I<Anonymous Subroutines>" |
| 515 |
msgstr "" |
| 516 |
|
| 517 |
#. type: IX |
| 518 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 519 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 520 |
#, no-wrap |
| 521 |
msgid "subroutine, anonymous subroutine, reference reference, subroutine scope, lexical closure lexical lexical scope" |
| 522 |
msgstr "" |
| 523 |
|
| 524 |
#. type: IX |
| 525 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 526 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 527 |
#, no-wrap |
| 528 |
msgid "Anonymous Subroutines" |
| 529 |
msgstr "" |
| 530 |
|
| 531 |
#. type: Plain text |
| 532 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 533 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 534 |
msgid "" |
| 535 |
"A reference to an anonymous subroutine can be created by using " |
| 536 |
"\\&CW<\\*(C`sub\\*(C'> without a subname:" |
| 537 |
msgstr "" |
| 538 |
|
| 539 |
#. type: Plain text |
| 540 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 541 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 542 |
#, no-wrap |
| 543 |
msgid "\\& $coderef = sub { print \"Boink!\\en\" };\n" |
| 544 |
msgstr "" |
| 545 |
|
| 546 |
#. type: Plain text |
| 547 |
#: debian-trixie debian-unstable |
| 548 |
msgid "" |
| 549 |
"Note the semicolon. Except for the code inside not being immediately " |
| 550 |
"executed, a CW<\\*(C`sub {}\\*(C'> is not so much a declaration as it is an " |
| 551 |
"operator, like CW<\\*(C`do{}\\*(C'> or CW<\\*(C`eval{}\\*(C'>. (However, no " |
| 552 |
"matter how many times you execute that particular line (unless you're in an " |
| 553 |
"\\&CW<eval(\"...\")>), CW<$coderef> will still have a reference to the " |
| 554 |
"I<same> anonymous subroutine.)" |
| 555 |
msgstr "" |
| 556 |
|
| 557 |
#. type: Plain text |
| 558 |
#: debian-trixie debian-unstable |
| 559 |
msgid "" |
| 560 |
"Anonymous subroutines act as closures with respect to B<my()> variables, " |
| 561 |
"that is, variables lexically visible within the current scope. Closure is a " |
| 562 |
"notion out of the Lisp world that says if you define an anonymous function " |
| 563 |
"in a particular lexical context, it pretends to run in that context even " |
| 564 |
"when it's called outside the context." |
| 565 |
msgstr "" |
| 566 |
|
| 567 |
#. type: Plain text |
| 568 |
#: debian-trixie debian-unstable |
| 569 |
msgid "" |
| 570 |
"In human terms, it's a funny way of passing arguments to a subroutine when " |
| 571 |
"you define it as well as when you call it. It's useful for setting up " |
| 572 |
"little bits of code to run later, such as callbacks. You can even do object-" |
| 573 |
"oriented stuff with it, though Perl already provides a different mechanism " |
| 574 |
"to do that--see perlobj." |
| 575 |
msgstr "" |
| 576 |
|
| 577 |
#. type: Plain text |
| 578 |
#: debian-trixie debian-unstable |
| 579 |
msgid "" |
| 580 |
"You might also think of closure as a way to write a subroutine template " |
| 581 |
"without using B<eval()>. Here's a small example of how closures work:" |
| 582 |
msgstr "" |
| 583 |
|
| 584 |
#. type: Plain text |
| 585 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 586 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 587 |
#, no-wrap |
| 588 |
msgid "" |
| 589 |
"\\& sub newprint {\n" |
| 590 |
"\\& my $x = shift;\n" |
| 591 |
"\\& return sub { my $y = shift; print \"$x, $y!\\en\"; };\n" |
| 592 |
"\\& }\n" |
| 593 |
"\\& $h = newprint(\"Howdy\");\n" |
| 594 |
"\\& $g = newprint(\"Greetings\");\n" |
| 595 |
"\\&\n" |
| 596 |
"\\& # Time passes...\n" |
| 597 |
"\\&\n" |
| 598 |
"\\& &$h(\"world\");\n" |
| 599 |
"\\& &$g(\"earthlings\");\n" |
| 600 |
msgstr "" |
| 601 |
|
| 602 |
#. type: Plain text |
| 603 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 604 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 605 |
msgid "This prints" |
| 606 |
msgstr "" |
| 607 |
|
| 608 |
#. type: Plain text |
| 609 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 610 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 611 |
#, no-wrap |
| 612 |
msgid "" |
| 613 |
"\\& Howdy, world!\n" |
| 614 |
"\\& Greetings, earthlings!\n" |
| 615 |
msgstr "" |
| 616 |
|
| 617 |
#. type: Plain text |
| 618 |
#: debian-trixie debian-unstable |
| 619 |
msgid "" |
| 620 |
"Note particularly that CW<$x> continues to refer to the value passed into " |
| 621 |
"B<newprint()> I<despite> \"my CW<$x>\" having gone out of scope by the time " |
| 622 |
"the anonymous subroutine runs. That's what a closure is all about." |
| 623 |
msgstr "" |
| 624 |
|
| 625 |
#. type: Plain text |
| 626 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 627 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 628 |
msgid "" |
| 629 |
"This applies only to lexical variables, by the way. Dynamic variables " |
| 630 |
"continue to work as they have always worked. Closure is not something that " |
| 631 |
"most Perl programmers need trouble themselves about to begin with." |
| 632 |
msgstr "" |
| 633 |
|
| 634 |
#. type: Plain text |
| 635 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 636 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 637 |
msgid "I<Constructors>" |
| 638 |
msgstr "" |
| 639 |
|
| 640 |
#. type: IX |
| 641 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 642 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 643 |
#, no-wrap |
| 644 |
msgid "constructor new" |
| 645 |
msgstr "" |
| 646 |
|
| 647 |
#. type: IX |
| 648 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 649 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 650 |
#, no-wrap |
| 651 |
msgid "Constructors" |
| 652 |
msgstr "" |
| 653 |
|
| 654 |
#. type: Plain text |
| 655 |
#: debian-trixie debian-unstable |
| 656 |
msgid "" |
| 657 |
"References are often returned by special subroutines called constructors. " |
| 658 |
"Perl objects are just references to a special type of object that happens to " |
| 659 |
"know which package it's associated with. Constructors are just special " |
| 660 |
"subroutines that know how to create that association. They do so by " |
| 661 |
"starting with an ordinary reference, and it remains an ordinary reference " |
| 662 |
"even while it's also being an object. Constructors are often named " |
| 663 |
"CW<new()>. You I<can> call them indirectly:" |
| 664 |
msgstr "" |
| 665 |
|
| 666 |
#. type: Plain text |
| 667 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 668 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 669 |
#, no-wrap |
| 670 |
msgid "\\& $objref = new Doggie( Tail =E<gt> \\*(Aqshort\\*(Aq, Ears =E<gt> \\*(Aqlong\\*(Aq );\n" |
| 671 |
msgstr "" |
| 672 |
|
| 673 |
#. type: Plain text |
| 674 |
#: debian-trixie debian-unstable |
| 675 |
msgid "" |
| 676 |
"But that can produce ambiguous syntax in certain cases, so it's often better " |
| 677 |
"to use the direct method invocation approach:" |
| 678 |
msgstr "" |
| 679 |
|
| 680 |
#. type: Plain text |
| 681 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 682 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 683 |
#, no-wrap |
| 684 |
msgid "" |
| 685 |
"\\& $objref = Doggie-E<gt>new(Tail =E<gt> \\*(Aqshort\\*(Aq, Ears =E<gt> \\*(Aqlong\\*(Aq);\n" |
| 686 |
"\\&\n" |
| 687 |
"\\& use Term::Cap;\n" |
| 688 |
"\\& $terminal = Term::Cap-E<gt>Tgetent( { OSPEED =E<gt> 9600 });\n" |
| 689 |
"\\&\n" |
| 690 |
"\\& use Tk;\n" |
| 691 |
"\\& $main = MainWindow-E<gt>new();\n" |
| 692 |
"\\& $menubar = $main-E<gt>Frame(-relief =E<gt> \"raised\",\n" |
| 693 |
"\\& -borderwidth =E<gt> 2)\n" |
| 694 |
msgstr "" |
| 695 |
|
| 696 |
#. type: Plain text |
| 697 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 698 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 699 |
msgid "" |
| 700 |
"This indirect object syntax is only available when \\&CW<\\*(C`use feature " |
| 701 |
"\"indirect\"\\*(C'> is in effect, and that is not the case when CW<\\*(C`use " |
| 702 |
"v5.36\\*(C'> (or higher) is requested, it is best to avoid indirect object " |
| 703 |
"syntax entirely." |
| 704 |
msgstr "" |
| 705 |
|
| 706 |
#. type: Plain text |
| 707 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 708 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 709 |
msgid "I<Autovivification>" |
| 710 |
msgstr "" |
| 711 |
|
| 712 |
#. type: IX |
| 713 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 714 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 715 |
#, no-wrap |
| 716 |
msgid "autovivification" |
| 717 |
msgstr "" |
| 718 |
|
| 719 |
#. type: IX |
| 720 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 721 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 722 |
#, no-wrap |
| 723 |
msgid "Autovivification" |
| 724 |
msgstr "" |
| 725 |
|
| 726 |
#. type: Plain text |
| 727 |
#: debian-trixie debian-unstable |
| 728 |
msgid "" |
| 729 |
"References of the appropriate type can spring into existence if you " |
| 730 |
"dereference them in a context that assumes they exist. Because we haven't " |
| 731 |
"talked about dereferencing yet, we can't show you any examples yet." |
| 732 |
msgstr "" |
| 733 |
|
| 734 |
#. type: Plain text |
| 735 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 736 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 737 |
msgid "I<Typeglob Slots>" |
| 738 |
msgstr "" |
| 739 |
|
| 740 |
#. type: IX |
| 741 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 742 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 743 |
#, no-wrap |
| 744 |
msgid "*foo{THING} *" |
| 745 |
msgstr "" |
| 746 |
|
| 747 |
#. type: IX |
| 748 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 749 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 750 |
#, no-wrap |
| 751 |
msgid "Typeglob Slots" |
| 752 |
msgstr "" |
| 753 |
|
| 754 |
#. type: Plain text |
| 755 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 756 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 757 |
msgid "" |
| 758 |
"A reference can be created by using a special syntax, lovingly known as the " |
| 759 |
"*foo{THING} syntax. *foo{THING} returns a reference to the THING slot in " |
| 760 |
"*foo (which is the symbol table entry which holds everything known as foo)." |
| 761 |
msgstr "" |
| 762 |
|
| 763 |
#. type: Plain text |
| 764 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 765 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 766 |
#, no-wrap |
| 767 |
msgid "" |
| 768 |
"\\& $scalarref = *foo{SCALAR};\n" |
| 769 |
"\\& $arrayref = *ARGV{ARRAY};\n" |
| 770 |
"\\& $hashref = *ENV{HASH};\n" |
| 771 |
"\\& $coderef = *handler{CODE};\n" |
| 772 |
"\\& $ioref = *STDIN{IO};\n" |
| 773 |
"\\& $globref = *foo{GLOB};\n" |
| 774 |
"\\& $formatref = *foo{FORMAT};\n" |
| 775 |
"\\& $globname = *foo{NAME}; # \"foo\"\n" |
| 776 |
"\\& $pkgname = *foo{PACKAGE}; # \"main\"\n" |
| 777 |
msgstr "" |
| 778 |
|
| 779 |
#. type: Plain text |
| 780 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 781 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 782 |
msgid "" |
| 783 |
"Most of these are self-explanatory, but CW<*foo{IO}> deserves special " |
| 784 |
"attention. It returns the IO handle, used for file handles (\"open\" in " |
| 785 |
"perlfunc), sockets (\"socket\" in perlfunc and \"socketpair\" in perlfunc), " |
| 786 |
"and directory handles (\"opendir\" in perlfunc). For compatibility with " |
| 787 |
"previous versions of Perl, CW<*foo{FILEHANDLE}> is a synonym for CW<*foo{IO}" |
| 788 |
">, though it is discouraged, to encourage a consistent use of one name: IO. " |
| 789 |
"On perls between v5.8 and v5.22, it will issue a deprecation warning, but " |
| 790 |
"this deprecation has since been rescinded." |
| 791 |
msgstr "" |
| 792 |
|
| 793 |
#. type: Plain text |
| 794 |
#: debian-trixie debian-unstable |
| 795 |
msgid "" |
| 796 |
"\\&CW<*foo{THING}> returns undef if that particular THING hasn't been used " |
| 797 |
"yet, except in the case of scalars. CW<*foo{SCALAR}> returns a reference to " |
| 798 |
"an anonymous scalar if CW<$foo> hasn't been used yet. This might change in " |
| 799 |
"a future release." |
| 800 |
msgstr "" |
| 801 |
|
| 802 |
#. type: Plain text |
| 803 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 804 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 805 |
msgid "" |
| 806 |
"\\&CW<*foo{NAME}> and CW<*foo{PACKAGE}> are the exception, in that they " |
| 807 |
"return strings, rather than references. These return the package and name " |
| 808 |
"of the typeglob itself, rather than one that has been assigned to it. So, " |
| 809 |
"after \\&CW<\\*(C`*foo=*Foo::bar\\*(C'>, CW<*foo> will become \"*Foo::bar\" " |
| 810 |
"when used as a string, but CW<*foo{PACKAGE}> and CW<*foo{NAME}> will " |
| 811 |
"continue to produce \"main\" and \"foo\", respectively." |
| 812 |
msgstr "" |
| 813 |
|
| 814 |
#. type: Plain text |
| 815 |
#: debian-trixie debian-unstable |
| 816 |
msgid "" |
| 817 |
"\\&CW<*foo{IO}> is an alternative to the CW<*HANDLE> mechanism given in " |
| 818 |
"\"Typeglobs and Filehandles\" in perldata for passing filehandles into or " |
| 819 |
"out of subroutines, or storing into larger data structures. Its " |
| 820 |
"disadvantage is that it won't create a new filehandle for you. Its " |
| 821 |
"advantage is that you have less risk of clobbering more than you want to " |
| 822 |
"with a typeglob assignment. (It still conflates file and directory handles, " |
| 823 |
"though.) However, if you assign the incoming value to a scalar instead of a " |
| 824 |
"typeglob as we do in the examples below, there's no risk of that happening." |
| 825 |
msgstr "" |
| 826 |
|
| 827 |
#. type: Plain text |
| 828 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 829 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 830 |
#, no-wrap |
| 831 |
msgid "" |
| 832 |
"\\& splutter(*STDOUT); # pass the whole glob\n" |
| 833 |
"\\& splutter(*STDOUT{IO}); # pass both file and dir handles\n" |
| 834 |
"\\&\n" |
| 835 |
"\\& sub splutter {\n" |
| 836 |
"\\& my $fh = shift;\n" |
| 837 |
"\\& print $fh \"her um well a hmmm\\en\";\n" |
| 838 |
"\\& }\n" |
| 839 |
"\\&\n" |
| 840 |
"\\& $rec = get_rec(*STDIN); # pass the whole glob\n" |
| 841 |
"\\& $rec = get_rec(*STDIN{IO}); # pass both file and dir handles\n" |
| 842 |
"\\&\n" |
| 843 |
"\\& sub get_rec {\n" |
| 844 |
"\\& my $fh = shift;\n" |
| 845 |
"\\& return scalar E<lt>$fhE<gt>;\n" |
| 846 |
"\\& }\n" |
| 847 |
msgstr "" |
| 848 |
|
| 849 |
#. type: IX |
| 850 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 851 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 852 |
#, no-wrap |
| 853 |
msgid "Using References" |
| 854 |
msgstr "" |
| 855 |
|
| 856 |
#. type: IX |
| 857 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 858 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 859 |
#, no-wrap |
| 860 |
msgid "reference, use dereferencing dereference" |
| 861 |
msgstr "" |
| 862 |
|
| 863 |
#. type: Plain text |
| 864 |
#: debian-trixie debian-unstable |
| 865 |
msgid "" |
| 866 |
"That's it for creating references. By now you're probably dying to know how " |
| 867 |
"to use references to get back to your long-lost data. There are several " |
| 868 |
"basic methods." |
| 869 |
msgstr "" |
| 870 |
|
| 871 |
#. type: Plain text |
| 872 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 873 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 874 |
msgid "I<Simple Scalar>" |
| 875 |
msgstr "" |
| 876 |
|
| 877 |
#. type: IX |
| 878 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 879 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 880 |
#, no-wrap |
| 881 |
msgid "Simple Scalar" |
| 882 |
msgstr "" |
| 883 |
|
| 884 |
#. type: Plain text |
| 885 |
#: debian-trixie debian-unstable |
| 886 |
msgid "" |
| 887 |
"Anywhere you'd put an identifier (or chain of identifiers) as part of a " |
| 888 |
"variable or subroutine name, you can replace the identifier with a simple " |
| 889 |
"scalar variable containing a reference of the correct type:" |
| 890 |
msgstr "" |
| 891 |
|
| 892 |
#. type: Plain text |
| 893 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 894 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 895 |
#, no-wrap |
| 896 |
msgid "" |
| 897 |
"\\& $bar = $$scalarref;\n" |
| 898 |
"\\& push(@$arrayref, $filename);\n" |
| 899 |
"\\& $$arrayref[0] = \"January\";\n" |
| 900 |
"\\& $$hashref{\"KEY\"} = \"VALUE\";\n" |
| 901 |
"\\& &$coderef(1,2,3);\n" |
| 902 |
"\\& print $globref \"output\\en\";\n" |
| 903 |
msgstr "" |
| 904 |
|
| 905 |
#. type: Plain text |
| 906 |
#: debian-trixie debian-unstable |
| 907 |
msgid "" |
| 908 |
"It's important to understand that we are specifically I<not> dereferencing " |
| 909 |
"\\&CW<$arrayref[0]> or CW<$hashref{\"KEY\"}> there. The dereference of the " |
| 910 |
"scalar variable happens I<before> it does any key lookups. Anything more " |
| 911 |
"complicated than a simple scalar variable must use methods 2 or 3 below. " |
| 912 |
"However, a \"simple scalar\" includes an identifier that itself uses method " |
| 913 |
"1 recursively. Therefore, the following prints \"howdy\"." |
| 914 |
msgstr "" |
| 915 |
|
| 916 |
#. type: Plain text |
| 917 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 918 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 919 |
#, no-wrap |
| 920 |
msgid "" |
| 921 |
"\\& $refrefref = \\e\\e\\e\"howdy\";\n" |
| 922 |
"\\& print $$$$refrefref;\n" |
| 923 |
msgstr "" |
| 924 |
|
| 925 |
#. type: Plain text |
| 926 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 927 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 928 |
msgid "I<Block>" |
| 929 |
msgstr "" |
| 930 |
|
| 931 |
#. type: IX |
| 932 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 933 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 934 |
#, no-wrap |
| 935 |
msgid "Block" |
| 936 |
msgstr "" |
| 937 |
|
| 938 |
#. type: Plain text |
| 939 |
#: debian-trixie debian-unstable |
| 940 |
msgid "" |
| 941 |
"Anywhere you'd put an identifier (or chain of identifiers) as part of a " |
| 942 |
"variable or subroutine name, you can replace the identifier with a BLOCK " |
| 943 |
"returning a reference of the correct type. In other words, the previous " |
| 944 |
"examples could be written like this:" |
| 945 |
msgstr "" |
| 946 |
|
| 947 |
#. type: Plain text |
| 948 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 949 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 950 |
#, no-wrap |
| 951 |
msgid "" |
| 952 |
"\\& $bar = ${$scalarref};\n" |
| 953 |
"\\& push(@{$arrayref}, $filename);\n" |
| 954 |
"\\& ${$arrayref}[0] = \"January\";\n" |
| 955 |
"\\& ${$hashref}{\"KEY\"} = \"VALUE\";\n" |
| 956 |
"\\& &{$coderef}(1,2,3);\n" |
| 957 |
"\\& $globref-E<gt>print(\"output\\en\"); # iff IO::Handle is loaded\n" |
| 958 |
msgstr "" |
| 959 |
|
| 960 |
#. type: Plain text |
| 961 |
#: debian-trixie debian-unstable |
| 962 |
msgid "" |
| 963 |
"Admittedly, it's a little silly to use the curlies in this case, but the " |
| 964 |
"BLOCK can contain any arbitrary expression, in particular, subscripted " |
| 965 |
"expressions:" |
| 966 |
msgstr "" |
| 967 |
|
| 968 |
#. type: Plain text |
| 969 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 970 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 971 |
#, no-wrap |
| 972 |
msgid "\\& &{ $dispatch{$index} }(1,2,3); # call correct routine\n" |
| 973 |
msgstr "" |
| 974 |
|
| 975 |
#. type: Plain text |
| 976 |
#: debian-trixie debian-unstable |
| 977 |
msgid "" |
| 978 |
"Because of being able to omit the curlies for the simple case of CW<$$x>, " |
| 979 |
"people often make the mistake of viewing the dereferencing symbols as proper " |
| 980 |
"operators, and wonder about their precedence. If they were, though, you " |
| 981 |
"could use parentheses instead of braces. That's not the case. Consider the " |
| 982 |
"difference below; case 0 is a short-hand version of case 1, \\&I<not> case 2:" |
| 983 |
msgstr "" |
| 984 |
|
| 985 |
#. type: Plain text |
| 986 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 987 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 988 |
#, no-wrap |
| 989 |
msgid "" |
| 990 |
"\\& $$hashref{\"KEY\"} = \"VALUE\"; # CASE 0\n" |
| 991 |
"\\& ${$hashref}{\"KEY\"} = \"VALUE\"; # CASE 1\n" |
| 992 |
"\\& ${$hashref{\"KEY\"}} = \"VALUE\"; # CASE 2\n" |
| 993 |
"\\& ${$hashref-E<gt>{\"KEY\"}} = \"VALUE\"; # CASE 3\n" |
| 994 |
msgstr "" |
| 995 |
|
| 996 |
#. type: Plain text |
| 997 |
#: debian-trixie debian-unstable |
| 998 |
msgid "" |
| 999 |
"Case 2 is also deceptive in that you're accessing a variable called " |
| 1000 |
"CW<%hashref>, not dereferencing through CW<$hashref> to the hash it's " |
| 1001 |
"presumably referencing. That would be case 3." |
| 1002 |
msgstr "" |
| 1003 |
|
| 1004 |
#. type: Plain text |
| 1005 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1006 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1007 |
msgid "I<Arrow Notation>" |
| 1008 |
msgstr "" |
| 1009 |
|
| 1010 |
#. type: IX |
| 1011 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1012 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1013 |
#, no-wrap |
| 1014 |
msgid "Arrow Notation" |
| 1015 |
msgstr "" |
| 1016 |
|
| 1017 |
#. type: Plain text |
| 1018 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1019 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1020 |
msgid "" |
| 1021 |
"Subroutine calls and lookups of individual array elements arise often enough " |
| 1022 |
"that it gets cumbersome to use method 2. As a form of syntactic sugar, the " |
| 1023 |
"examples for method 2 may be written:" |
| 1024 |
msgstr "" |
| 1025 |
|
| 1026 |
#. type: Plain text |
| 1027 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1028 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1029 |
#, no-wrap |
| 1030 |
msgid "" |
| 1031 |
"\\& $arrayref-E<gt>[0] = \"January\"; # Array element\n" |
| 1032 |
"\\& $hashref-E<gt>{\"KEY\"} = \"VALUE\"; # Hash element\n" |
| 1033 |
"\\& $coderef-E<gt>(1,2,3); # Subroutine call\n" |
| 1034 |
msgstr "" |
| 1035 |
|
| 1036 |
#. type: Plain text |
| 1037 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1038 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1039 |
msgid "" |
| 1040 |
"The left side of the arrow can be any expression returning a reference, " |
| 1041 |
"including a previous dereference. Note that CW<$array[$x]> is I<not> the " |
| 1042 |
"same thing as CW<\\*(C`$array-E<gt>[$x]\\*(C'> here:" |
| 1043 |
msgstr "" |
| 1044 |
|
| 1045 |
#. type: Plain text |
| 1046 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1047 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1048 |
#, no-wrap |
| 1049 |
msgid "\\& $array[$x]-E<gt>{\"foo\"}-E<gt>[0] = \"January\";\n" |
| 1050 |
msgstr "" |
| 1051 |
|
| 1052 |
#. type: Plain text |
| 1053 |
#: debian-trixie debian-unstable |
| 1054 |
msgid "" |
| 1055 |
"This is one of the cases we mentioned earlier in which references could " |
| 1056 |
"spring into existence when in an lvalue context. Before this statement, " |
| 1057 |
"CW<$array[$x]> may have been undefined. If so, it's automatically defined " |
| 1058 |
"with a hash reference so that we can look up \\&CW<\\*(C`{\"foo\"}\\*(C'> in " |
| 1059 |
"it. Likewise CW<\\*(C`$array[$x]-E<gt>{\"foo\"}\\*(C'> will automatically " |
| 1060 |
"get defined with an array reference so that we can look up " |
| 1061 |
"CW<\\*(C`[0]\\*(C'> in it. This process is called I<autovivification>." |
| 1062 |
msgstr "" |
| 1063 |
|
| 1064 |
#. type: Plain text |
| 1065 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1066 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1067 |
msgid "" |
| 1068 |
"One more thing here. The arrow is optional I<between> brackets subscripts, " |
| 1069 |
"so you can shrink the above down to" |
| 1070 |
msgstr "" |
| 1071 |
|
| 1072 |
#. type: Plain text |
| 1073 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1074 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1075 |
#, no-wrap |
| 1076 |
msgid "\\& $array[$x]{\"foo\"}[0] = \"January\";\n" |
| 1077 |
msgstr "" |
| 1078 |
|
| 1079 |
#. type: Plain text |
| 1080 |
#: debian-trixie debian-unstable |
| 1081 |
msgid "" |
| 1082 |
"Which, in the degenerate case of using only ordinary arrays, gives you " |
| 1083 |
"multidimensional arrays just like C's:" |
| 1084 |
msgstr "" |
| 1085 |
|
| 1086 |
#. type: Plain text |
| 1087 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1088 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1089 |
#, no-wrap |
| 1090 |
msgid "\\& $score[$x][$y][$z] += 42;\n" |
| 1091 |
msgstr "" |
| 1092 |
|
| 1093 |
#. type: Plain text |
| 1094 |
#: debian-trixie debian-unstable |
| 1095 |
msgid "" |
| 1096 |
"Well, okay, not entirely like C's arrays, actually. C doesn't know how to " |
| 1097 |
"grow its arrays on demand. Perl does." |
| 1098 |
msgstr "" |
| 1099 |
|
| 1100 |
#. type: Plain text |
| 1101 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1102 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1103 |
msgid "I<Objects>" |
| 1104 |
msgstr "" |
| 1105 |
|
| 1106 |
#. type: IX |
| 1107 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1108 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1109 |
#, no-wrap |
| 1110 |
msgid "Objects" |
| 1111 |
msgstr "" |
| 1112 |
|
| 1113 |
#. type: Plain text |
| 1114 |
#: debian-trixie debian-unstable |
| 1115 |
msgid "" |
| 1116 |
"If a reference happens to be a reference to an object, then there are " |
| 1117 |
"probably methods to access the things referred to, and you should probably " |
| 1118 |
"stick to those methods unless you're in the class package that defines the " |
| 1119 |
"object's methods. In other words, be nice, and don't violate the object's " |
| 1120 |
"encapsulation without a very good reason. Perl does not enforce " |
| 1121 |
"encapsulation. We are not totalitarians here. We do expect some basic " |
| 1122 |
"civility though." |
| 1123 |
msgstr "" |
| 1124 |
|
| 1125 |
#. type: Plain text |
| 1126 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1127 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1128 |
msgid "I<Miscellaneous Usage>" |
| 1129 |
msgstr "" |
| 1130 |
|
| 1131 |
#. type: IX |
| 1132 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1133 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1134 |
#, no-wrap |
| 1135 |
msgid "Miscellaneous Usage" |
| 1136 |
msgstr "" |
| 1137 |
|
| 1138 |
#. type: Plain text |
| 1139 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1140 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1141 |
msgid "" |
| 1142 |
"Using a string or number as a reference produces a symbolic reference, as " |
| 1143 |
"explained above. Using a reference as a number produces an integer " |
| 1144 |
"representing its storage location in memory. The only useful thing to be " |
| 1145 |
"done with this is to compare two references numerically to see whether they " |
| 1146 |
"refer to the same location." |
| 1147 |
msgstr "" |
| 1148 |
|
| 1149 |
#. type: IX |
| 1150 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1151 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1152 |
#, no-wrap |
| 1153 |
msgid "reference, numeric context" |
| 1154 |
msgstr "" |
| 1155 |
|
| 1156 |
#. type: Plain text |
| 1157 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1158 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1159 |
#, no-wrap |
| 1160 |
msgid "" |
| 1161 |
"\\& if ($ref1 == $ref2) { # cheap numeric compare of references\n" |
| 1162 |
"\\& print \"refs 1 and 2 refer to the same thing\\en\";\n" |
| 1163 |
"\\& }\n" |
| 1164 |
msgstr "" |
| 1165 |
|
| 1166 |
#. type: Plain text |
| 1167 |
#: debian-trixie debian-unstable |
| 1168 |
msgid "" |
| 1169 |
"Using a reference as a string produces both its referent's type, including " |
| 1170 |
"any package blessing as described in perlobj, as well as the numeric address " |
| 1171 |
"expressed in hex. The B<ref()> operator returns just the type of thing the " |
| 1172 |
"reference is pointing to, without the address. See \"ref\" in perlfunc for " |
| 1173 |
"details and examples of its use." |
| 1174 |
msgstr "" |
| 1175 |
|
| 1176 |
#. type: IX |
| 1177 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1178 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1179 |
#, no-wrap |
| 1180 |
msgid "reference, string context" |
| 1181 |
msgstr "" |
| 1182 |
|
| 1183 |
#. type: Plain text |
| 1184 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1185 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1186 |
msgid "" |
| 1187 |
"The B<bless()> operator may be used to associate the object a reference " |
| 1188 |
"points to with a package functioning as an object class. See perlobj." |
| 1189 |
msgstr "" |
| 1190 |
|
| 1191 |
#. type: Plain text |
| 1192 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1193 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1194 |
msgid "" |
| 1195 |
"A typeglob may be dereferenced the same way a reference can, because the " |
| 1196 |
"dereference syntax always indicates the type of reference desired. So " |
| 1197 |
"CW<\\*(C`${*foo}\\*(C'> and CW<\\*(C`${\\e$foo}\\*(C'> both indicate the " |
| 1198 |
"same scalar variable." |
| 1199 |
msgstr "" |
| 1200 |
|
| 1201 |
#. type: Plain text |
| 1202 |
#: debian-trixie debian-unstable |
| 1203 |
msgid "Here's a trick for interpolating a subroutine call into a string:" |
| 1204 |
msgstr "" |
| 1205 |
|
| 1206 |
#. type: Plain text |
| 1207 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1208 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1209 |
#, no-wrap |
| 1210 |
msgid "\\& print \"My sub returned @{[mysub(1,2,3)]} that time.\\en\";\n" |
| 1211 |
msgstr "" |
| 1212 |
|
| 1213 |
#. type: Plain text |
| 1214 |
#: debian-trixie debian-unstable |
| 1215 |
msgid "" |
| 1216 |
"The way it works is that when the CW<\\*(C`@{...}\\*(C'> is seen in the " |
| 1217 |
"double-quoted string, it's evaluated as a block. The block creates a " |
| 1218 |
"reference to an anonymous array containing the results of the call to " |
| 1219 |
"CW<\\*(C`mysub(1,2,3)\\*(C'>. So the whole block returns a reference to an " |
| 1220 |
"array, which is then dereferenced by CW<\\*(C`@{...}\\*(C'> and stuck into " |
| 1221 |
"the double-quoted string. This chicanery is also useful for arbitrary " |
| 1222 |
"expressions:" |
| 1223 |
msgstr "" |
| 1224 |
|
| 1225 |
#. type: Plain text |
| 1226 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1227 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1228 |
#, no-wrap |
| 1229 |
msgid "\\& print \"That yields @{[$n + 5]} widgets\\en\";\n" |
| 1230 |
msgstr "" |
| 1231 |
|
| 1232 |
#. type: Plain text |
| 1233 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1234 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1235 |
msgid "" |
| 1236 |
"Similarly, an expression that returns a reference to a scalar can be " |
| 1237 |
"dereferenced via CW<\\*(C`${...}\\*(C'>. Thus, the above expression may be " |
| 1238 |
"written as:" |
| 1239 |
msgstr "" |
| 1240 |
|
| 1241 |
#. type: Plain text |
| 1242 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1243 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1244 |
#, no-wrap |
| 1245 |
msgid "\\& print \"That yields ${\\e($n + 5)} widgets\\en\";\n" |
| 1246 |
msgstr "" |
| 1247 |
|
| 1248 |
#. type: IX |
| 1249 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1250 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1251 |
#, no-wrap |
| 1252 |
msgid "Circular References" |
| 1253 |
msgstr "" |
| 1254 |
|
| 1255 |
#. type: IX |
| 1256 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1257 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1258 |
#, no-wrap |
| 1259 |
msgid "circular reference reference, circular" |
| 1260 |
msgstr "" |
| 1261 |
|
| 1262 |
#. type: Plain text |
| 1263 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1264 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1265 |
msgid "" |
| 1266 |
"It is possible to create a \"circular reference\" in Perl, which can lead to " |
| 1267 |
"memory leaks. A circular reference occurs when two references contain a " |
| 1268 |
"reference to each other, like this:" |
| 1269 |
msgstr "" |
| 1270 |
|
| 1271 |
#. type: Plain text |
| 1272 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1273 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1274 |
#, no-wrap |
| 1275 |
msgid "" |
| 1276 |
"\\& my $foo = {};\n" |
| 1277 |
"\\& my $bar = { foo =E<gt> $foo };\n" |
| 1278 |
"\\& $foo-E<gt>{bar} = $bar;\n" |
| 1279 |
msgstr "" |
| 1280 |
|
| 1281 |
#. type: Plain text |
| 1282 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1283 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1284 |
msgid "You can also create a circular reference with a single variable:" |
| 1285 |
msgstr "" |
| 1286 |
|
| 1287 |
#. type: Plain text |
| 1288 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1289 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1290 |
#, no-wrap |
| 1291 |
msgid "" |
| 1292 |
"\\& my $foo;\n" |
| 1293 |
"\\& $foo = \\e$foo;\n" |
| 1294 |
msgstr "" |
| 1295 |
|
| 1296 |
#. type: Plain text |
| 1297 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1298 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1299 |
msgid "" |
| 1300 |
"In this case, the reference count for the variables will never reach 0, and " |
| 1301 |
"the references will never be garbage-collected. This can lead to memory " |
| 1302 |
"leaks." |
| 1303 |
msgstr "" |
| 1304 |
|
| 1305 |
#. type: Plain text |
| 1306 |
#: debian-trixie debian-unstable |
| 1307 |
msgid "" |
| 1308 |
"Because objects in Perl are implemented as references, it's possible to have " |
| 1309 |
"circular references with objects as well. Imagine a TreeNode class where " |
| 1310 |
"each node references its parent and child nodes. Any node with a parent will " |
| 1311 |
"be part of a circular reference." |
| 1312 |
msgstr "" |
| 1313 |
|
| 1314 |
#. type: Plain text |
| 1315 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1316 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1317 |
msgid "" |
| 1318 |
"You can break circular references by creating a \"weak reference\". A weak " |
| 1319 |
"reference does not increment the reference count for a variable, which means " |
| 1320 |
"that the object can go out of scope and be destroyed. You can weaken a " |
| 1321 |
"reference with the CW<\\*(C`weaken\\*(C'> function exported by the " |
| 1322 |
"Scalar::Util module, or available as CW<\\*(C`builtin::weaken\\*(C'> " |
| 1323 |
"directly in Perl version 5.35.7 or later." |
| 1324 |
msgstr "" |
| 1325 |
|
| 1326 |
#. type: Plain text |
| 1327 |
#: debian-trixie debian-unstable |
| 1328 |
msgid "Here's how we can make the first example safer:" |
| 1329 |
msgstr "" |
| 1330 |
|
| 1331 |
#. type: Plain text |
| 1332 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1333 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1334 |
#, no-wrap |
| 1335 |
msgid "" |
| 1336 |
"\\& use Scalar::Util \\*(Aqweaken\\*(Aq;\n" |
| 1337 |
"\\&\n" |
| 1338 |
"\\& my $foo = {};\n" |
| 1339 |
"\\& my $bar = { foo =E<gt> $foo };\n" |
| 1340 |
"\\& $foo-E<gt>{bar} = $bar;\n" |
| 1341 |
"\\&\n" |
| 1342 |
"\\& weaken $foo-E<gt>{bar};\n" |
| 1343 |
msgstr "" |
| 1344 |
|
| 1345 |
#. type: Plain text |
| 1346 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1347 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1348 |
msgid "" |
| 1349 |
"The reference from CW<$foo> to CW<$bar> has been weakened. When the " |
| 1350 |
"\\&CW<$bar> variable goes out of scope, it will be garbage-collected. The " |
| 1351 |
"next time you look at the value of the CW<\\*(C`$foo-E<gt>{bar}\\*(C'> key, " |
| 1352 |
"it will be CW<\\*(C`undef\\*(C'>." |
| 1353 |
msgstr "" |
| 1354 |
|
| 1355 |
#. type: Plain text |
| 1356 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1357 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1358 |
msgid "" |
| 1359 |
"This action at a distance can be confusing, so you should be careful with " |
| 1360 |
"your use of weaken. You should weaken the reference in the variable that " |
| 1361 |
"will go out of scope I<first>. That way, the longer-lived variable will " |
| 1362 |
"contain the expected reference until it goes out of scope." |
| 1363 |
msgstr "" |
| 1364 |
|
| 1365 |
#. type: IX |
| 1366 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1367 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1368 |
#, no-wrap |
| 1369 |
msgid "Symbolic references" |
| 1370 |
msgstr "" |
| 1371 |
|
| 1372 |
#. type: Plain text |
| 1373 |
#: debian-trixie debian-unstable |
| 1374 |
msgid "" |
| 1375 |
"We said that references spring into existence as necessary if they are " |
| 1376 |
"undefined, but we didn't say what happens if a value used as a reference is " |
| 1377 |
"already defined, but I<isn't> a hard reference. If you use it as a " |
| 1378 |
"reference, it'll be treated as a symbolic reference. That is, the value of " |
| 1379 |
"the scalar is taken to be the I<name> of a variable, rather than a direct " |
| 1380 |
"link to a (possibly) anonymous value." |
| 1381 |
msgstr "" |
| 1382 |
|
| 1383 |
#. type: Plain text |
| 1384 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1385 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1386 |
msgid "People frequently expect it to work like this. So it does." |
| 1387 |
msgstr "" |
| 1388 |
|
| 1389 |
#. type: Plain text |
| 1390 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1391 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1392 |
#, no-wrap |
| 1393 |
msgid "" |
| 1394 |
"\\& $name = \"foo\";\n" |
| 1395 |
"\\& $$name = 1; # Sets $foo\n" |
| 1396 |
"\\& ${$name} = 2; # Sets $foo\n" |
| 1397 |
"\\& ${$name x 2} = 3; # Sets $foofoo\n" |
| 1398 |
"\\& $name-E<gt>[0] = 4; # Sets $foo[0]\n" |
| 1399 |
"\\& @$name = (); # Clears @foo\n" |
| 1400 |
"\\& &$name(); # Calls &foo()\n" |
| 1401 |
"\\& $pack = \"THAT\";\n" |
| 1402 |
"\\& ${\"${pack}::$name\"} = 5; # Sets $THAT::foo without eval\n" |
| 1403 |
msgstr "" |
| 1404 |
|
| 1405 |
#. type: Plain text |
| 1406 |
#: debian-trixie debian-unstable |
| 1407 |
msgid "" |
| 1408 |
"This is powerful, and slightly dangerous, in that it's possible to intend " |
| 1409 |
"(with the utmost sincerity) to use a hard reference, and accidentally use a " |
| 1410 |
"symbolic reference instead. To protect against that, you can say" |
| 1411 |
msgstr "" |
| 1412 |
|
| 1413 |
#. type: Plain text |
| 1414 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1415 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1416 |
#, no-wrap |
| 1417 |
msgid "\\& use strict \\*(Aqrefs\\*(Aq;\n" |
| 1418 |
msgstr "" |
| 1419 |
|
| 1420 |
#. type: Plain text |
| 1421 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1422 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1423 |
msgid "" |
| 1424 |
"and then only hard references will be allowed for the rest of the enclosing " |
| 1425 |
"block. An inner block may countermand that with" |
| 1426 |
msgstr "" |
| 1427 |
|
| 1428 |
#. type: Plain text |
| 1429 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1430 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1431 |
#, no-wrap |
| 1432 |
msgid "\\& no strict \\*(Aqrefs\\*(Aq;\n" |
| 1433 |
msgstr "" |
| 1434 |
|
| 1435 |
#. type: Plain text |
| 1436 |
#: debian-trixie debian-unstable |
| 1437 |
msgid "" |
| 1438 |
"Only package variables (globals, even if localized) are visible to symbolic " |
| 1439 |
"references. Lexical variables (declared with B<my()>) aren't in a symbol " |
| 1440 |
"table, and thus are invisible to this mechanism. For example:" |
| 1441 |
msgstr "" |
| 1442 |
|
| 1443 |
#. type: Plain text |
| 1444 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1445 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1446 |
#, no-wrap |
| 1447 |
msgid "" |
| 1448 |
"\\& local $value = 10;\n" |
| 1449 |
"\\& $ref = \"value\";\n" |
| 1450 |
"\\& {\n" |
| 1451 |
"\\& my $value = 20;\n" |
| 1452 |
"\\& print $$ref;\n" |
| 1453 |
"\\& }\n" |
| 1454 |
msgstr "" |
| 1455 |
|
| 1456 |
#. type: Plain text |
| 1457 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1458 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1459 |
msgid "" |
| 1460 |
"This will still print 10, not 20. Remember that B<local()> affects package " |
| 1461 |
"variables, which are all \"global\" to the package." |
| 1462 |
msgstr "" |
| 1463 |
|
| 1464 |
#. type: IX |
| 1465 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1466 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1467 |
#, no-wrap |
| 1468 |
msgid "Not-so-symbolic references" |
| 1469 |
msgstr "" |
| 1470 |
|
| 1471 |
#. type: Plain text |
| 1472 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1473 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1474 |
msgid "" |
| 1475 |
"Brackets around a symbolic reference can simply serve to isolate an " |
| 1476 |
"identifier or variable name from the rest of an expression, just as they " |
| 1477 |
"always have within a string. For example," |
| 1478 |
msgstr "" |
| 1479 |
|
| 1480 |
#. type: Plain text |
| 1481 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1482 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1483 |
#, no-wrap |
| 1484 |
msgid "" |
| 1485 |
"\\& $push = \"pop on \";\n" |
| 1486 |
"\\& print \"${push}over\";\n" |
| 1487 |
msgstr "" |
| 1488 |
|
| 1489 |
#. type: Plain text |
| 1490 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1491 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1492 |
msgid "" |
| 1493 |
"has always meant to print \"pop on over\", even though push is a reserved " |
| 1494 |
"word. This is generalized to work the same without the enclosing double " |
| 1495 |
"quotes, so that" |
| 1496 |
msgstr "" |
| 1497 |
|
| 1498 |
#. type: Plain text |
| 1499 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1500 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1501 |
#, no-wrap |
| 1502 |
msgid "\\& print ${push} . \"over\";\n" |
| 1503 |
msgstr "" |
| 1504 |
|
| 1505 |
#. type: Plain text |
| 1506 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1507 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1508 |
msgid "and even" |
| 1509 |
msgstr "" |
| 1510 |
|
| 1511 |
#. type: Plain text |
| 1512 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1513 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1514 |
#, no-wrap |
| 1515 |
msgid "\\& print ${ push } . \"over\";\n" |
| 1516 |
msgstr "" |
| 1517 |
|
| 1518 |
#. type: Plain text |
| 1519 |
#: debian-trixie debian-unstable |
| 1520 |
msgid "" |
| 1521 |
"will have the same effect. This construct is I<not> considered to be a " |
| 1522 |
"symbolic reference when you're using strict refs:" |
| 1523 |
msgstr "" |
| 1524 |
|
| 1525 |
#. type: Plain text |
| 1526 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1527 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1528 |
#, no-wrap |
| 1529 |
msgid "" |
| 1530 |
"\\& use strict \\*(Aqrefs\\*(Aq;\n" |
| 1531 |
"\\& ${ bareword }; # Okay, means $bareword.\n" |
| 1532 |
"\\& ${ \"bareword\" }; # Error, symbolic reference.\n" |
| 1533 |
msgstr "" |
| 1534 |
|
| 1535 |
#. type: Plain text |
| 1536 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1537 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1538 |
msgid "" |
| 1539 |
"Similarly, because of all the subscripting that is done using single words, " |
| 1540 |
"the same rule applies to any bareword that is used for subscripting a hash. " |
| 1541 |
"So now, instead of writing" |
| 1542 |
msgstr "" |
| 1543 |
|
| 1544 |
#. type: Plain text |
| 1545 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1546 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1547 |
#, no-wrap |
| 1548 |
msgid "\\& $hash{ \"aaa\" }{ \"bbb\" }{ \"ccc\" }\n" |
| 1549 |
msgstr "" |
| 1550 |
|
| 1551 |
#. type: Plain text |
| 1552 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1553 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1554 |
msgid "you can write just" |
| 1555 |
msgstr "" |
| 1556 |
|
| 1557 |
#. type: Plain text |
| 1558 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1559 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1560 |
#, no-wrap |
| 1561 |
msgid "\\& $hash{ aaa }{ bbb }{ ccc }\n" |
| 1562 |
msgstr "" |
| 1563 |
|
| 1564 |
#. type: Plain text |
| 1565 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1566 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1567 |
msgid "" |
| 1568 |
"and not worry about whether the subscripts are reserved words. In the rare " |
| 1569 |
"event that you do wish to do something like" |
| 1570 |
msgstr "" |
| 1571 |
|
| 1572 |
#. type: Plain text |
| 1573 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1574 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1575 |
#, no-wrap |
| 1576 |
msgid "\\& $hash{ shift }\n" |
| 1577 |
msgstr "" |
| 1578 |
|
| 1579 |
#. type: Plain text |
| 1580 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1581 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1582 |
msgid "" |
| 1583 |
"you can force interpretation as a reserved word by adding anything that " |
| 1584 |
"makes it more than a bareword:" |
| 1585 |
msgstr "" |
| 1586 |
|
| 1587 |
#. type: Plain text |
| 1588 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1589 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1590 |
#, no-wrap |
| 1591 |
msgid "" |
| 1592 |
"\\& $hash{ shift() }\n" |
| 1593 |
"\\& $hash{ +shift }\n" |
| 1594 |
"\\& $hash{ shift @_ }\n" |
| 1595 |
msgstr "" |
| 1596 |
|
| 1597 |
#. type: Plain text |
| 1598 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1599 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1600 |
msgid "" |
| 1601 |
"The CW<\\*(C`use warnings\\*(C'> pragma or the B<-w> switch will warn you if " |
| 1602 |
"it interprets a reserved word as a string. But it will no longer warn you " |
| 1603 |
"about using lowercase words, because the string is effectively quoted." |
| 1604 |
msgstr "" |
| 1605 |
|
| 1606 |
#. type: IX |
| 1607 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1608 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1609 |
#, no-wrap |
| 1610 |
msgid "Pseudo-hashes: Using an array as a hash" |
| 1611 |
msgstr "" |
| 1612 |
|
| 1613 |
#. type: IX |
| 1614 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1615 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1616 |
#, no-wrap |
| 1617 |
msgid "pseudo-hash pseudo hash pseudohash" |
| 1618 |
msgstr "" |
| 1619 |
|
| 1620 |
#. type: Plain text |
| 1621 |
#: debian-trixie debian-unstable |
| 1622 |
msgid "" |
| 1623 |
"Pseudo-hashes have been removed from Perl. The 'fields' pragma remains " |
| 1624 |
"available." |
| 1625 |
msgstr "" |
| 1626 |
|
| 1627 |
#. type: IX |
| 1628 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1629 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1630 |
#, no-wrap |
| 1631 |
msgid "Function Templates" |
| 1632 |
msgstr "" |
| 1633 |
|
| 1634 |
#. type: IX |
| 1635 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1636 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1637 |
#, no-wrap |
| 1638 |
msgid "scope, lexical closure lexical lexical scope subroutine, nested sub, nested subroutine, local sub, local" |
| 1639 |
msgstr "" |
| 1640 |
|
| 1641 |
#. type: Plain text |
| 1642 |
#: debian-trixie debian-unstable |
| 1643 |
msgid "" |
| 1644 |
"As explained above, an anonymous function with access to the lexical " |
| 1645 |
"variables visible when that function was compiled, creates a closure. It " |
| 1646 |
"retains access to those variables even though it doesn't get run until " |
| 1647 |
"later, such as in a signal handler or a Tk callback." |
| 1648 |
msgstr "" |
| 1649 |
|
| 1650 |
#. type: Plain text |
| 1651 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1652 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1653 |
msgid "" |
| 1654 |
"Using a closure as a function template allows us to generate many functions " |
| 1655 |
"that act similarly. Suppose you wanted functions named after the colors " |
| 1656 |
"that generated HTML font changes for the various colors:" |
| 1657 |
msgstr "" |
| 1658 |
|
| 1659 |
#. type: Plain text |
| 1660 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1661 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1662 |
#, no-wrap |
| 1663 |
msgid "\\& print \"Be \", red(\"careful\"), \"with that \", green(\"light\");\n" |
| 1664 |
msgstr "" |
| 1665 |
|
| 1666 |
#. type: Plain text |
| 1667 |
#: debian-trixie debian-unstable |
| 1668 |
msgid "" |
| 1669 |
"The B<red()> and B<green()> functions would be similar. To create these, " |
| 1670 |
"we'll assign a closure to a typeglob of the name of the function we're " |
| 1671 |
"trying to build." |
| 1672 |
msgstr "" |
| 1673 |
|
| 1674 |
#. type: Plain text |
| 1675 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1676 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1677 |
#, no-wrap |
| 1678 |
msgid "" |
| 1679 |
"\\& @colors = qw(red blue green yellow orange purple violet);\n" |
| 1680 |
"\\& for my $name (@colors) {\n" |
| 1681 |
"\\& no strict \\*(Aqrefs\\*(Aq; # allow symbol table manipulation\n" |
| 1682 |
"\\& *$name = *{uc $name} = sub { \"E<lt>FONT COLOR=\\*(Aq$name\\*(AqE<gt>@_E<lt>/FONTE<gt>\" };\n" |
| 1683 |
"\\& }\n" |
| 1684 |
msgstr "" |
| 1685 |
|
| 1686 |
#. type: Plain text |
| 1687 |
#: debian-trixie debian-unstable |
| 1688 |
msgid "" |
| 1689 |
"Now all those different functions appear to exist independently. You can " |
| 1690 |
"call B<red()>, B<RED()>, B<blue()>, B<BLUE()>, B<green()>, etc. This " |
| 1691 |
"technique saves on both compile time and memory use, and is less error-prone " |
| 1692 |
"as well, since syntax checks happen at compile time. It's critical that any " |
| 1693 |
"variables in the anonymous subroutine be lexicals in order to create a " |
| 1694 |
"proper closure. That's the reasons for the CW<\\*(C`my\\*(C'> on the loop " |
| 1695 |
"iteration variable." |
| 1696 |
msgstr "" |
| 1697 |
|
| 1698 |
#. type: Plain text |
| 1699 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1700 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1701 |
msgid "" |
| 1702 |
"This is one of the only places where giving a prototype to a closure makes " |
| 1703 |
"much sense. If you wanted to impose scalar context on the arguments of " |
| 1704 |
"these functions (probably not a wise idea for this particular example), you " |
| 1705 |
"could have written it this way instead:" |
| 1706 |
msgstr "" |
| 1707 |
|
| 1708 |
#. type: Plain text |
| 1709 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1710 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1711 |
#, no-wrap |
| 1712 |
msgid "\\& *$name = sub ($) { \"E<lt>FONT COLOR=\\*(Aq$name\\*(AqE<gt>$_[0]E<lt>/FONTE<gt>\" };\n" |
| 1713 |
msgstr "" |
| 1714 |
|
| 1715 |
#. type: Plain text |
| 1716 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1717 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1718 |
msgid "" |
| 1719 |
"However, since prototype checking happens at compile time, the assignment " |
| 1720 |
"above happens too late to be of much use. You could address this by putting " |
| 1721 |
"the whole loop of assignments within a BEGIN block, forcing it to occur " |
| 1722 |
"during compilation." |
| 1723 |
msgstr "" |
| 1724 |
|
| 1725 |
#. type: Plain text |
| 1726 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1727 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1728 |
msgid "" |
| 1729 |
"Access to lexicals that change over time--like those in the " |
| 1730 |
"CW<\\*(C`for\\*(C'> loop above, basically aliases to elements from the " |
| 1731 |
"surrounding lexical scopes-- only works with anonymous subs, not with named " |
| 1732 |
"subroutines. Generally said, named subroutines do not nest properly and " |
| 1733 |
"should only be declared in the main package scope." |
| 1734 |
msgstr "" |
| 1735 |
|
| 1736 |
#. type: Plain text |
| 1737 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1738 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1739 |
msgid "" |
| 1740 |
"This is because named subroutines are created at compile time so their " |
| 1741 |
"lexical variables get assigned to the parent lexicals from the first " |
| 1742 |
"execution of the parent block. If a parent scope is entered a second time, " |
| 1743 |
"its lexicals are created again, while the nested subs still reference the " |
| 1744 |
"old ones." |
| 1745 |
msgstr "" |
| 1746 |
|
| 1747 |
#. type: Plain text |
| 1748 |
#: debian-trixie debian-unstable |
| 1749 |
msgid "" |
| 1750 |
"Anonymous subroutines get to capture each time you execute the " |
| 1751 |
"CW<\\*(C`sub\\*(C'> operator, as they are created on the fly. If you are " |
| 1752 |
"accustomed to using nested subroutines in other programming languages with " |
| 1753 |
"their own private variables, you'll have to work at it a bit in Perl. The " |
| 1754 |
"intuitive coding of this type of thing incurs mysterious warnings about " |
| 1755 |
"\"will not stay shared\" due to the reasons explained above. For example, " |
| 1756 |
"this won't work:" |
| 1757 |
msgstr "" |
| 1758 |
|
| 1759 |
#. type: Plain text |
| 1760 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1761 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1762 |
#, no-wrap |
| 1763 |
msgid "" |
| 1764 |
"\\& sub outer {\n" |
| 1765 |
"\\& my $x = $_[0] + 35;\n" |
| 1766 |
"\\& sub inner { return $x * 19 } # WRONG\n" |
| 1767 |
"\\& return $x + inner();\n" |
| 1768 |
"\\& }\n" |
| 1769 |
msgstr "" |
| 1770 |
|
| 1771 |
#. type: Plain text |
| 1772 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1773 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1774 |
msgid "A work-around is the following:" |
| 1775 |
msgstr "" |
| 1776 |
|
| 1777 |
#. type: Plain text |
| 1778 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1779 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1780 |
#, no-wrap |
| 1781 |
msgid "" |
| 1782 |
"\\& sub outer {\n" |
| 1783 |
"\\& my $x = $_[0] + 35;\n" |
| 1784 |
"\\& local *inner = sub { return $x * 19 };\n" |
| 1785 |
"\\& return $x + inner();\n" |
| 1786 |
"\\& }\n" |
| 1787 |
msgstr "" |
| 1788 |
|
| 1789 |
#. type: Plain text |
| 1790 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1791 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1792 |
msgid "" |
| 1793 |
"Now B<inner()> can only be called from within B<outer()>, because of the " |
| 1794 |
"temporary assignments of the anonymous subroutine. But when it does, it has " |
| 1795 |
"normal access to the lexical variable CW<$x> from the scope of \\&B<outer()> " |
| 1796 |
"at the time outer is invoked." |
| 1797 |
msgstr "" |
| 1798 |
|
| 1799 |
#. type: Plain text |
| 1800 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1801 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1802 |
msgid "" |
| 1803 |
"This has the interesting effect of creating a function local to another " |
| 1804 |
"function, something not normally supported in Perl." |
| 1805 |
msgstr "" |
| 1806 |
|
| 1807 |
#. type: IX |
| 1808 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1809 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1810 |
#, no-wrap |
| 1811 |
msgid "Postfix Dereference Syntax" |
| 1812 |
msgstr "" |
| 1813 |
|
| 1814 |
#. type: Plain text |
| 1815 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1816 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1817 |
msgid "" |
| 1818 |
"Beginning in v5.20.0, a postfix syntax for using references is available. " |
| 1819 |
"It behaves as described in \"Using References\", but instead of a prefixed " |
| 1820 |
"sigil, a postfixed sigil-and-star is used." |
| 1821 |
msgstr "" |
| 1822 |
|
| 1823 |
#. type: Plain text |
| 1824 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1825 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1826 |
msgid "For example:" |
| 1827 |
msgstr "" |
| 1828 |
|
| 1829 |
#. type: Plain text |
| 1830 |
#: debian-trixie debian-unstable |
| 1831 |
#, no-wrap |
| 1832 |
msgid "" |
| 1833 |
"\\& $r = \\e@a;\n" |
| 1834 |
"\\& @b = $r-E<gt>@*; # equivalent to @$r or @{ $r }\n" |
| 1835 |
"\\&\n" |
| 1836 |
"\\& $r = [ 1, [ 2, 3 ], 4 ];\n" |
| 1837 |
"\\& $r-E<gt>[1]-E<gt>@*; # equivalent to @{ $r-E<gt>[1] }\n" |
| 1838 |
msgstr "" |
| 1839 |
|
| 1840 |
#. type: Plain text |
| 1841 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1842 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1843 |
msgid "" |
| 1844 |
"In Perl 5.20 and 5.22, this syntax must be enabled with CW<use feature " |
| 1845 |
"\\&\\*(Aqpostderef\\*(Aq>. As of Perl 5.24, no feature declarations are " |
| 1846 |
"required to make it available." |
| 1847 |
msgstr "" |
| 1848 |
|
| 1849 |
#. type: Plain text |
| 1850 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1851 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1852 |
msgid "" |
| 1853 |
"Postfix dereference should work in all circumstances where block (circumfix) " |
| 1854 |
"dereference worked, and should be entirely equivalent. This syntax allows " |
| 1855 |
"dereferencing to be written and read entirely left-to-right. The following " |
| 1856 |
"equivalencies are defined:" |
| 1857 |
msgstr "" |
| 1858 |
|
| 1859 |
#. type: Plain text |
| 1860 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1861 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1862 |
#, no-wrap |
| 1863 |
msgid "" |
| 1864 |
"\\& $sref-E<gt>$*; # same as ${ $sref }\n" |
| 1865 |
"\\& $aref-E<gt>@*; # same as @{ $aref }\n" |
| 1866 |
"\\& $aref-E<gt>$#*; # same as $#{ $aref }\n" |
| 1867 |
"\\& $href-E<gt>%*; # same as %{ $href }\n" |
| 1868 |
"\\& $cref-E<gt>&*; # same as &{ $cref }\n" |
| 1869 |
"\\& $gref-E<gt>**; # same as *{ $gref }\n" |
| 1870 |
msgstr "" |
| 1871 |
|
| 1872 |
#. type: Plain text |
| 1873 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1874 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1875 |
msgid "" |
| 1876 |
"Note especially that CW<\\*(C`$cref-E<gt>&*\\*(C'> is I<not> equivalent to " |
| 1877 |
"CW<$cref-E<gt>()>, and can serve different purposes." |
| 1878 |
msgstr "" |
| 1879 |
|
| 1880 |
#. type: Plain text |
| 1881 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1882 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1883 |
msgid "" |
| 1884 |
"Glob elements can be extracted through the postfix dereferencing feature:" |
| 1885 |
msgstr "" |
| 1886 |
|
| 1887 |
#. type: Plain text |
| 1888 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1889 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1890 |
#, no-wrap |
| 1891 |
msgid "\\& $gref-E<gt>*{SCALAR}; # same as *{ $gref }{SCALAR}\n" |
| 1892 |
msgstr "" |
| 1893 |
|
| 1894 |
#. type: Plain text |
| 1895 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1896 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1897 |
msgid "" |
| 1898 |
"Postfix array and scalar dereferencing I<can> be used in interpolating " |
| 1899 |
"strings (double quotes or the CW<\\*(C`qq\\*(C'> operator), but only if the " |
| 1900 |
"\\&CW<\\*(C`postderef_qq\\*(C'> feature is enabled. Interpolation of postfix " |
| 1901 |
"array highest index access (CW<\\*(C`-E<gt>$#*\\*(C'>) is also supported " |
| 1902 |
"when the CW<\\*(C`postderef_qq\\*(C'> feature is enabled." |
| 1903 |
msgstr "" |
| 1904 |
|
| 1905 |
#. type: IX |
| 1906 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1907 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1908 |
#, no-wrap |
| 1909 |
msgid "Postfix Reference Slicing" |
| 1910 |
msgstr "" |
| 1911 |
|
| 1912 |
#. type: Plain text |
| 1913 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1914 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1915 |
msgid "" |
| 1916 |
"Value slices of arrays and hashes may also be taken with postfix " |
| 1917 |
"dereferencing notation, with the following equivalencies:" |
| 1918 |
msgstr "" |
| 1919 |
|
| 1920 |
#. type: Plain text |
| 1921 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1922 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1923 |
#, no-wrap |
| 1924 |
msgid "" |
| 1925 |
"\\& $aref-E<gt>@[ ... ]; # same as @$aref[ ... ]\n" |
| 1926 |
"\\& $href-E<gt>@{ ... }; # same as @$href{ ... }\n" |
| 1927 |
msgstr "" |
| 1928 |
|
| 1929 |
#. type: Plain text |
| 1930 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1931 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1932 |
msgid "" |
| 1933 |
"Postfix key/value pair slicing, added in 5.20.0 and documented in the Key/" |
| 1934 |
"Value Hash Slices section of perldata, also behaves as expected:" |
| 1935 |
msgstr "" |
| 1936 |
|
| 1937 |
#. type: Plain text |
| 1938 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1939 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1940 |
#, no-wrap |
| 1941 |
msgid "" |
| 1942 |
"\\& $aref-E<gt>%[ ... ]; # same as %$aref[ ... ]\n" |
| 1943 |
"\\& $href-E<gt>%{ ... }; # same as %$href{ ... }\n" |
| 1944 |
msgstr "" |
| 1945 |
|
| 1946 |
#. type: Plain text |
| 1947 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1948 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1949 |
msgid "" |
| 1950 |
"As with postfix array, postfix value slice dereferencing I<can> be used in " |
| 1951 |
"interpolating strings (double quotes or the CW<\\*(C`qq\\*(C'> operator), " |
| 1952 |
"but only if the CW<\\*(C`postderef_qq\\*(C'> feature is enabled." |
| 1953 |
msgstr "" |
| 1954 |
|
| 1955 |
#. type: IX |
| 1956 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1957 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1958 |
#, no-wrap |
| 1959 |
msgid "Assigning to References" |
| 1960 |
msgstr "" |
| 1961 |
|
| 1962 |
#. type: Plain text |
| 1963 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1964 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1965 |
msgid "" |
| 1966 |
"Beginning in v5.22.0, the referencing operator can be assigned to. It " |
| 1967 |
"performs an aliasing operation, so that the variable name referenced on the " |
| 1968 |
"left-hand side becomes an alias for the thing referenced on the right-hand " |
| 1969 |
"side:" |
| 1970 |
msgstr "" |
| 1971 |
|
| 1972 |
#. type: Plain text |
| 1973 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1974 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1975 |
#, no-wrap |
| 1976 |
msgid "" |
| 1977 |
"\\& \\e$x = \\e$y; # $x and $y now point to the same scalar\n" |
| 1978 |
"\\& \\e&foo = \\e&bar; # foo() now means bar()\n" |
| 1979 |
msgstr "" |
| 1980 |
|
| 1981 |
#. type: Plain text |
| 1982 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1983 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1984 |
msgid "" |
| 1985 |
"This syntax must be enabled with CW<\\*(C`use feature " |
| 1986 |
"\\*(Aqrefaliasing\\*(Aq\\*(C'>. It is experimental, and will warn by " |
| 1987 |
"default unless CW<no warnings \\&\\*(Aqexperimental::refaliasing\\*(Aq> is " |
| 1988 |
"in effect." |
| 1989 |
msgstr "" |
| 1990 |
|
| 1991 |
#. type: Plain text |
| 1992 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1993 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1994 |
msgid "" |
| 1995 |
"These forms may be assigned to, and cause the right-hand side to be " |
| 1996 |
"evaluated in scalar context:" |
| 1997 |
msgstr "" |
| 1998 |
|
| 1999 |
#. type: Plain text |
| 2000 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2001 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2002 |
#, no-wrap |
| 2003 |
msgid "" |
| 2004 |
"\\& \\e$scalar\n" |
| 2005 |
"\\& \\e@array\n" |
| 2006 |
"\\& \\e%hash\n" |
| 2007 |
"\\& \\e&sub\n" |
| 2008 |
"\\& \\emy $scalar\n" |
| 2009 |
"\\& \\emy @array\n" |
| 2010 |
"\\& \\emy %hash\n" |
| 2011 |
"\\& \\estate $scalar # or @array, etc.\n" |
| 2012 |
"\\& \\eour $scalar # etc.\n" |
| 2013 |
"\\& \\elocal $scalar # etc.\n" |
| 2014 |
"\\& \\elocal our $scalar # etc.\n" |
| 2015 |
"\\& \\e$some_array[$index]\n" |
| 2016 |
"\\& \\e$some_hash{$key}\n" |
| 2017 |
"\\& \\elocal $some_array[$index]\n" |
| 2018 |
"\\& \\elocal $some_hash{$key}\n" |
| 2019 |
"\\& condition ? \\e$this : \\e$that[0] # etc.\n" |
| 2020 |
msgstr "" |
| 2021 |
|
| 2022 |
#. type: Plain text |
| 2023 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2024 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2025 |
msgid "" |
| 2026 |
"Slicing operations and parentheses cause the right-hand side to be evaluated " |
| 2027 |
"in list context:" |
| 2028 |
msgstr "" |
| 2029 |
|
| 2030 |
#. type: Plain text |
| 2031 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2032 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2033 |
#, no-wrap |
| 2034 |
msgid "" |
| 2035 |
"\\& \\e@array[5..7]\n" |
| 2036 |
"\\& (\\e@array[5..7])\n" |
| 2037 |
"\\& \\e(@array[5..7])\n" |
| 2038 |
"\\& \\e@hash{\\*(Aqfoo\\*(Aq,\\*(Aqbar\\*(Aq}\n" |
| 2039 |
"\\& (\\e@hash{\\*(Aqfoo\\*(Aq,\\*(Aqbar\\*(Aq})\n" |
| 2040 |
"\\& \\e(@hash{\\*(Aqfoo\\*(Aq,\\*(Aqbar\\*(Aq})\n" |
| 2041 |
"\\& (\\e$scalar)\n" |
| 2042 |
"\\& \\e($scalar)\n" |
| 2043 |
"\\& \\e(my $scalar)\n" |
| 2044 |
"\\& \\emy($scalar)\n" |
| 2045 |
"\\& (\\e@array)\n" |
| 2046 |
"\\& (\\e%hash)\n" |
| 2047 |
"\\& (\\e&sub)\n" |
| 2048 |
"\\& \\e(&sub)\n" |
| 2049 |
"\\& \\e($foo, @bar, %baz)\n" |
| 2050 |
"\\& (\\e$foo, \\e@bar, \\e%baz)\n" |
| 2051 |
msgstr "" |
| 2052 |
|
| 2053 |
#. type: Plain text |
| 2054 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2055 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2056 |
msgid "" |
| 2057 |
"Each element on the right-hand side must be a reference to a datum of the " |
| 2058 |
"right type. Parentheses immediately surrounding an array (and possibly also " |
| 2059 |
"CW<\\*(C`my\\*(C'>/CW<\\*(C`state\\*(C'>/CW<\\*(C`our\\*(C'>/" |
| 2060 |
"CW<\\*(C`local\\*(C'>) will make each element of the array an alias to the " |
| 2061 |
"corresponding scalar referenced on the right-hand side:" |
| 2062 |
msgstr "" |
| 2063 |
|
| 2064 |
#. type: Plain text |
| 2065 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2066 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2067 |
#, no-wrap |
| 2068 |
msgid "" |
| 2069 |
"\\& \\e(@x) = \\e(@y); # @x and @y now have the same elements\n" |
| 2070 |
"\\& \\emy(@x) = \\e(@y); # likewise\n" |
| 2071 |
"\\& \\e(my @x) = \\e(@y); # likewise\n" |
| 2072 |
"\\& push @x, 3; # but now @x has an extra element that @y lacks\n" |
| 2073 |
"\\& \\e(@x) = (\\e$x, \\e$y, \\e$z); # @x now contains $x, $y, and $z\n" |
| 2074 |
msgstr "" |
| 2075 |
|
| 2076 |
#. type: Plain text |
| 2077 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2078 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2079 |
msgid "" |
| 2080 |
"Combining that form with CW<\\*(C`local\\*(C'> and putting parentheses " |
| 2081 |
"immediately around a hash are forbidden (because it is not clear what they " |
| 2082 |
"should do):" |
| 2083 |
msgstr "" |
| 2084 |
|
| 2085 |
#. type: Plain text |
| 2086 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2087 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2088 |
#, no-wrap |
| 2089 |
msgid "" |
| 2090 |
"\\& \\elocal(@array) = foo(); # WRONG\n" |
| 2091 |
"\\& \\e(%hash) = bar(); # WRONG\n" |
| 2092 |
msgstr "" |
| 2093 |
|
| 2094 |
#. type: Plain text |
| 2095 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2096 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2097 |
msgid "" |
| 2098 |
"Assignment to references and non-references may be combined in lists and " |
| 2099 |
"conditional ternary expressions, as long as the values on the right-hand " |
| 2100 |
"side are the right type for each element on the left, though this may make " |
| 2101 |
"for obfuscated code:" |
| 2102 |
msgstr "" |
| 2103 |
|
| 2104 |
#. type: Plain text |
| 2105 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2106 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2107 |
#, no-wrap |
| 2108 |
msgid "" |
| 2109 |
"\\& (my $tom, \\emy $dick, \\emy @harry) = (\\e1, \\e2, [1..3]);\n" |
| 2110 |
"\\& # $tom is now \\e1\n" |
| 2111 |
"\\& # $dick is now 2 (read-only)\n" |
| 2112 |
"\\& # @harry is (1,2,3)\n" |
| 2113 |
"\\&\n" |
| 2114 |
"\\& my $type = ref $thingy;\n" |
| 2115 |
"\\& ($type ? $type eq \\*(AqARRAY\\*(Aq ? \\e@foo : \\e$bar : $baz) = $thingy;\n" |
| 2116 |
msgstr "" |
| 2117 |
|
| 2118 |
#. type: Plain text |
| 2119 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2120 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2121 |
msgid "" |
| 2122 |
"A reference assignment in list context returns a list of references to each " |
| 2123 |
"left-hand value. So for example" |
| 2124 |
msgstr "" |
| 2125 |
|
| 2126 |
#. type: Plain text |
| 2127 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2128 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2129 |
#, no-wrap |
| 2130 |
msgid "\\& @b = ((\\e$l1, \\e$l2, \\e(@a)) = (\\e$r1, \\e$r2, $\\er3, \\e$4));\n" |
| 2131 |
msgstr "" |
| 2132 |
|
| 2133 |
#. type: Plain text |
| 2134 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2135 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2136 |
msgid "is equivalent to" |
| 2137 |
msgstr "" |
| 2138 |
|
| 2139 |
#. type: Plain text |
| 2140 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2141 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2142 |
#, no-wrap |
| 2143 |
msgid "" |
| 2144 |
"\\& (\\e$l1, \\e$l2, \\e(@a)) = (\\e$r1, \\e$r2, $\\er3, \\e$4);\n" |
| 2145 |
"\\& @b = (\\e$l1, \\e$l2, \\e$a[0], \\e$a[1]);\n" |
| 2146 |
msgstr "" |
| 2147 |
|
| 2148 |
#. type: Plain text |
| 2149 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2150 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2151 |
msgid "" |
| 2152 |
"The CW<\\*(C`foreach\\*(C'> loop can also take a reference constructor for " |
| 2153 |
"its loop variable, though the syntax is limited to one of the following, " |
| 2154 |
"with an optional CW<\\*(C`my\\*(C'>, CW<\\*(C`state\\*(C'>, or " |
| 2155 |
"CW<\\*(C`our\\*(C'> after the backslash:" |
| 2156 |
msgstr "" |
| 2157 |
|
| 2158 |
#. type: Plain text |
| 2159 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2160 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2161 |
#, no-wrap |
| 2162 |
msgid "" |
| 2163 |
"\\& \\e$s\n" |
| 2164 |
"\\& \\e@a\n" |
| 2165 |
"\\& \\e%h\n" |
| 2166 |
"\\& \\e&c\n" |
| 2167 |
msgstr "" |
| 2168 |
|
| 2169 |
#. type: Plain text |
| 2170 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2171 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2172 |
msgid "" |
| 2173 |
"No parentheses are permitted. This feature is particularly useful for " |
| 2174 |
"arrays-of-arrays, or arrays-of-hashes:" |
| 2175 |
msgstr "" |
| 2176 |
|
| 2177 |
#. type: Plain text |
| 2178 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2179 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2180 |
#, no-wrap |
| 2181 |
msgid "" |
| 2182 |
"\\& foreach \\emy @a (@array_of_arrays) {\n" |
| 2183 |
"\\& frobnicate($a[0], $a[-1]);\n" |
| 2184 |
"\\& }\n" |
| 2185 |
"\\&\n" |
| 2186 |
"\\& foreach \\emy %h (@array_of_hashes) {\n" |
| 2187 |
"\\& $h{gelastic}++ if $h{type} eq \\*(Aqfunny\\*(Aq;\n" |
| 2188 |
"\\& }\n" |
| 2189 |
msgstr "" |
| 2190 |
|
| 2191 |
#. type: Plain text |
| 2192 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2193 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2194 |
msgid "" |
| 2195 |
"\\&B<CAVEAT:> Aliasing does not work correctly with closures. If you try to " |
| 2196 |
"alias lexical variables from an inner subroutine or CW<\\*(C`eval\\*(C'>, " |
| 2197 |
"the aliasing will only be visible within that inner sub, and will not affect " |
| 2198 |
"the outer subroutine where the variables are declared. This bizarre " |
| 2199 |
"behavior is subject to change." |
| 2200 |
msgstr "" |
| 2201 |
|
| 2202 |
#. type: IX |
| 2203 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2204 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2205 |
#, no-wrap |
| 2206 |
msgid "Declaring a Reference to a Variable" |
| 2207 |
msgstr "" |
| 2208 |
|
| 2209 |
#. type: Plain text |
| 2210 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2211 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2212 |
msgid "" |
| 2213 |
"Beginning in v5.26.0, the referencing operator can come after " |
| 2214 |
"CW<\\*(C`my\\*(C'>, \\&CW<\\*(C`state\\*(C'>, CW<\\*(C`our\\*(C'>, or " |
| 2215 |
"CW<\\*(C`local\\*(C'>. This syntax must be enabled with CW<\\*(C`use " |
| 2216 |
"feature \\*(Aqdeclared_refs\\*(Aq\\*(C'>. It is experimental, and will warn " |
| 2217 |
"by default unless CW<\\*(C`no warnings " |
| 2218 |
"\\*(Aqexperimental::refaliasing\\*(Aq\\*(C'> is in effect." |
| 2219 |
msgstr "" |
| 2220 |
|
| 2221 |
#. type: Plain text |
| 2222 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2223 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2224 |
msgid "This feature makes these:" |
| 2225 |
msgstr "" |
| 2226 |
|
| 2227 |
#. type: Plain text |
| 2228 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2229 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2230 |
#, no-wrap |
| 2231 |
msgid "" |
| 2232 |
"\\& my \\e$x;\n" |
| 2233 |
"\\& our \\e$y;\n" |
| 2234 |
msgstr "" |
| 2235 |
|
| 2236 |
#. type: Plain text |
| 2237 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2238 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2239 |
msgid "equivalent to:" |
| 2240 |
msgstr "" |
| 2241 |
|
| 2242 |
#. type: Plain text |
| 2243 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2244 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2245 |
#, no-wrap |
| 2246 |
msgid "" |
| 2247 |
"\\& \\emy $x;\n" |
| 2248 |
"\\& \\eour $x;\n" |
| 2249 |
msgstr "" |
| 2250 |
|
| 2251 |
#. type: Plain text |
| 2252 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2253 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2254 |
msgid "" |
| 2255 |
"It is intended mainly for use in assignments to references (see \"Assigning " |
| 2256 |
"to References\", above). It also allows the backslash to be used on just " |
| 2257 |
"some items in a list of declared variables:" |
| 2258 |
msgstr "" |
| 2259 |
|
| 2260 |
#. type: Plain text |
| 2261 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2262 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2263 |
#, no-wrap |
| 2264 |
msgid "\\& my ($foo, \\e@bar, \\e%baz); # equivalent to: my $foo, \\emy(@bar, %baz);\n" |
| 2265 |
msgstr "" |
| 2266 |
|
| 2267 |
#. type: IX |
| 2268 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2269 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2270 |
#, no-wrap |
| 2271 |
msgid "WARNING: Don't use references as hash keys" |
| 2272 |
msgstr "" |
| 2273 |
|
| 2274 |
#. type: IX |
| 2275 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2276 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2277 |
#, no-wrap |
| 2278 |
msgid "reference, string context reference, use as hash key" |
| 2279 |
msgstr "" |
| 2280 |
|
| 2281 |
#. type: Plain text |
| 2282 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2283 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2284 |
msgid "" |
| 2285 |
"You may not (usefully) use a reference as the key to a hash. It will be " |
| 2286 |
"converted into a string:" |
| 2287 |
msgstr "" |
| 2288 |
|
| 2289 |
#. type: Plain text |
| 2290 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2291 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2292 |
#, no-wrap |
| 2293 |
msgid "\\& $x{ \\e$x } = $x;\n" |
| 2294 |
msgstr "" |
| 2295 |
|
| 2296 |
#. type: Plain text |
| 2297 |
#: debian-trixie debian-unstable |
| 2298 |
msgid "" |
| 2299 |
"If you try to dereference the key, it won't do a hard dereference, and you " |
| 2300 |
"won't accomplish what you're attempting. You might want to do something " |
| 2301 |
"more like" |
| 2302 |
msgstr "" |
| 2303 |
|
| 2304 |
#. type: Plain text |
| 2305 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2306 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2307 |
#, no-wrap |
| 2308 |
msgid "" |
| 2309 |
"\\& $r = \\e@a;\n" |
| 2310 |
"\\& $x{ $r } = $r;\n" |
| 2311 |
msgstr "" |
| 2312 |
|
| 2313 |
#. type: Plain text |
| 2314 |
#: debian-trixie debian-unstable |
| 2315 |
msgid "" |
| 2316 |
"And then at least you can use the B<values()>, which will be real refs, " |
| 2317 |
"instead of the B<keys()>, which won't." |
| 2318 |
msgstr "" |
| 2319 |
|
| 2320 |
#. type: Plain text |
| 2321 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2322 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2323 |
msgid "" |
| 2324 |
"The standard Tie::RefHash module provides a convenient workaround to this." |
| 2325 |
msgstr "" |
| 2326 |
|
| 2327 |
#. type: IX |
| 2328 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2329 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2330 |
#, no-wrap |
| 2331 |
msgid "SEE ALSO" |
| 2332 |
msgstr "" |
| 2333 |
|
| 2334 |
#. type: Plain text |
| 2335 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2336 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2337 |
msgid "" |
| 2338 |
"Besides the obvious documents, source code can be instructive. Some " |
| 2339 |
"pathological examples of the use of references can be found in the I<t/op/" |
| 2340 |
"ref.t> regression test in the Perl source directory." |
| 2341 |
msgstr "" |
| 2342 |
|
| 2343 |
#. type: Plain text |
| 2344 |
#: debian-trixie debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 2345 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2346 |
msgid "" |
| 2347 |
"See also perldsc and perllol for how to use references to create complex " |
| 2348 |
"data structures, and perlootut and perlobj for how to use them to create " |
| 2349 |
"objects." |
| 2350 |
msgstr "" |
| 2351 |
|
| 2352 |
#. type: TH |
| 2353 |
#: debian-unstable |
| 2354 |
#, no-wrap |
| 2355 |
msgid "2025-11-16" |
| 2356 |
msgstr "" |
| 2357 |
|
| 2358 |
#. type: TH |
| 2359 |
#: fedora-44 opensuse-leap-16-1 opensuse-tumbleweed |
| 2360 |
#, no-wrap |
| 2361 |
msgid "2026-03-09" |
| 2362 |
msgstr "" |
| 2363 |
|
| 2364 |
#. type: TH |
| 2365 |
#: fedora-44 opensuse-leap-16-1 opensuse-tumbleweed |
| 2366 |
#, no-wrap |
| 2367 |
msgid "perl v5.42.1" |
| 2368 |
msgstr "" |
| 2369 |
|
| 2370 |
#. type: Plain text |
| 2371 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2372 |
#: opensuse-tumbleweed |
| 2373 |
msgid "" |
| 2374 |
"Symbolic references are names of variables or other objects, just as a " |
| 2375 |
"symbolic link in a Unix filesystem contains merely the name of a file. The " |
| 2376 |
"CW<*glob> notation is something of a symbolic reference. (Symbolic " |
| 2377 |
"references are sometimes called \"soft references\", but please don\\*(Aqt " |
| 2378 |
"call them that; references are confusing enough without useless synonyms.)" |
| 2379 |
msgstr "" |
| 2380 |
|
| 2381 |
#. type: Plain text |
| 2382 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2383 |
#: opensuse-tumbleweed |
| 2384 |
msgid "" |
| 2385 |
"References are easy to use in Perl. There is just one overriding principle: " |
| 2386 |
"in general, Perl does no implicit referencing or dereferencing. When a " |
| 2387 |
"scalar is holding a reference, it always behaves as a simple scalar. It " |
| 2388 |
"doesn\\*(Aqt magically start being an array or hash or subroutine; you have " |
| 2389 |
"to tell it explicitly to do so, by dereferencing it." |
| 2390 |
msgstr "" |
| 2391 |
|
| 2392 |
#. type: Plain text |
| 2393 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2394 |
#: opensuse-tumbleweed |
| 2395 |
msgid "" |
| 2396 |
"By using the backslash operator on a variable, subroutine, or value. (This " |
| 2397 |
"works much like the & (address-of) operator in C.) This typically creates " |
| 2398 |
"I<another> reference to a variable, because there\\*(Aqs already a reference " |
| 2399 |
"to the variable in the symbol table. But the symbol table reference might " |
| 2400 |
"go away, and you\\*(Aqll still have the reference that the backslash " |
| 2401 |
"returned. Here are some examples:" |
| 2402 |
msgstr "" |
| 2403 |
|
| 2404 |
#. type: Plain text |
| 2405 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2406 |
#: opensuse-tumbleweed |
| 2407 |
msgid "" |
| 2408 |
"It isn\\*(Aqt possible to create a true reference to an IO handle " |
| 2409 |
"(filehandle or dirhandle) using the backslash operator. The most you can " |
| 2410 |
"get is a reference to a typeglob, which is actually a complete symbol table " |
| 2411 |
"entry. But see the explanation of the CW<*foo{THING}> syntax below. " |
| 2412 |
"However, you can still use type globs and globrefs as though they were IO " |
| 2413 |
"handles." |
| 2414 |
msgstr "" |
| 2415 |
|
| 2416 |
#. type: Plain text |
| 2417 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2418 |
#: opensuse-tumbleweed |
| 2419 |
msgid "" |
| 2420 |
"Here we\\*(Aqve created a reference to an anonymous array of three elements " |
| 2421 |
"whose final element is itself a reference to another anonymous array of " |
| 2422 |
"three elements. (The multidimensional syntax described later can be used to " |
| 2423 |
"access this. For example, after the above, CW<\\*(C`$arrayref-E<gt>[2]" |
| 2424 |
"[1]\\*(C'> would have the value \"b\".)" |
| 2425 |
msgstr "" |
| 2426 |
|
| 2427 |
#. type: Plain text |
| 2428 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2429 |
#: opensuse-tumbleweed |
| 2430 |
msgid "" |
| 2431 |
"Taking a reference to an enumerated list is not the same as using square " |
| 2432 |
"brackets--instead it\\*(Aqs the same as creating a list of references!" |
| 2433 |
msgstr "" |
| 2434 |
|
| 2435 |
#. type: Plain text |
| 2436 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2437 |
#: opensuse-tumbleweed |
| 2438 |
msgid "" |
| 2439 |
"Because curly brackets (braces) are used for several other things including " |
| 2440 |
"BLOCKs, you may occasionally have to disambiguate braces at the beginning of " |
| 2441 |
"a statement by putting a CW<\\*(C`+\\*(C'> or a CW<\\*(C`return\\*(C'> in " |
| 2442 |
"front so that Perl realizes the opening brace isn\\*(Aqt starting a BLOCK. " |
| 2443 |
"The economy and mnemonic value of using curlies is deemed worth this " |
| 2444 |
"occasional extra hassle." |
| 2445 |
msgstr "" |
| 2446 |
|
| 2447 |
#. type: Plain text |
| 2448 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2449 |
#: opensuse-tumbleweed |
| 2450 |
msgid "" |
| 2451 |
"Note the semicolon. Except for the code inside not being immediately " |
| 2452 |
"executed, a CW<\\*(C`sub {}\\*(C'> is not so much a declaration as it is an " |
| 2453 |
"operator, like CW<\\*(C`do{}\\*(C'> or CW<\\*(C`eval{}\\*(C'>. (However, no " |
| 2454 |
"matter how many times you execute that particular line (unless you\\*(Aqre " |
| 2455 |
"in an \\&CW<eval(\"...\")>), CW<$coderef> will still have a reference to the " |
| 2456 |
"I<same> anonymous subroutine.)" |
| 2457 |
msgstr "" |
| 2458 |
|
| 2459 |
#. type: Plain text |
| 2460 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2461 |
#: opensuse-tumbleweed |
| 2462 |
msgid "" |
| 2463 |
"Anonymous subroutines act as closures with respect to B<my()> variables, " |
| 2464 |
"that is, variables lexically visible within the current scope. Closure is a " |
| 2465 |
"notion out of the Lisp world that says if you define an anonymous function " |
| 2466 |
"in a particular lexical context, it pretends to run in that context even " |
| 2467 |
"when it\\*(Aqs called outside the context." |
| 2468 |
msgstr "" |
| 2469 |
|
| 2470 |
#. type: Plain text |
| 2471 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2472 |
#: opensuse-tumbleweed |
| 2473 |
msgid "" |
| 2474 |
"In human terms, it\\*(Aqs a funny way of passing arguments to a subroutine " |
| 2475 |
"when you define it as well as when you call it. It\\*(Aqs useful for " |
| 2476 |
"setting up little bits of code to run later, such as callbacks. You can " |
| 2477 |
"even do object-oriented stuff with it, though Perl already provides a " |
| 2478 |
"different mechanism to do that--see perlobj." |
| 2479 |
msgstr "" |
| 2480 |
|
| 2481 |
#. type: Plain text |
| 2482 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2483 |
#: opensuse-tumbleweed |
| 2484 |
msgid "" |
| 2485 |
"You might also think of closure as a way to write a subroutine template " |
| 2486 |
"without using B<eval()>. Here\\*(Aqs a small example of how closures work:" |
| 2487 |
msgstr "" |
| 2488 |
|
| 2489 |
#. type: Plain text |
| 2490 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2491 |
#: opensuse-tumbleweed |
| 2492 |
msgid "" |
| 2493 |
"Note particularly that CW<$x> continues to refer to the value passed into " |
| 2494 |
"B<newprint()> I<despite> \"my CW<$x>\" having gone out of scope by the time " |
| 2495 |
"the anonymous subroutine runs. That\\*(Aqs what a closure is all about." |
| 2496 |
msgstr "" |
| 2497 |
|
| 2498 |
#. type: Plain text |
| 2499 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2500 |
#: opensuse-tumbleweed |
| 2501 |
msgid "" |
| 2502 |
"References are often returned by special subroutines called constructors. " |
| 2503 |
"Perl objects are just references to a special type of object that happens to " |
| 2504 |
"know which package it\\*(Aqs associated with. Constructors are just special " |
| 2505 |
"subroutines that know how to create that association. They do so by " |
| 2506 |
"starting with an ordinary reference, and it remains an ordinary reference " |
| 2507 |
"even while it\\*(Aqs also being an object. Constructors are often named " |
| 2508 |
"CW<new()>. You I<can> call them indirectly:" |
| 2509 |
msgstr "" |
| 2510 |
|
| 2511 |
#. type: Plain text |
| 2512 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2513 |
#: opensuse-tumbleweed |
| 2514 |
msgid "" |
| 2515 |
"But that can produce ambiguous syntax in certain cases, so it\\*(Aqs often " |
| 2516 |
"better to use the direct method invocation approach:" |
| 2517 |
msgstr "" |
| 2518 |
|
| 2519 |
#. type: Plain text |
| 2520 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2521 |
#: opensuse-tumbleweed |
| 2522 |
msgid "" |
| 2523 |
"References of the appropriate type can spring into existence if you " |
| 2524 |
"dereference them in a context that assumes they exist. Because we " |
| 2525 |
"haven\\*(Aqt talked about dereferencing yet, we can\\*(Aqt show you any " |
| 2526 |
"examples yet." |
| 2527 |
msgstr "" |
| 2528 |
|
| 2529 |
#. type: Plain text |
| 2530 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2531 |
#: opensuse-tumbleweed |
| 2532 |
msgid "" |
| 2533 |
"\\&CW<*foo{THING}> returns undef if that particular THING hasn\\*(Aqt been " |
| 2534 |
"used yet, except in the case of scalars. CW<*foo{SCALAR}> returns a " |
| 2535 |
"reference to an anonymous scalar if CW<$foo> hasn\\*(Aqt been used yet. " |
| 2536 |
"This might change in a future release." |
| 2537 |
msgstr "" |
| 2538 |
|
| 2539 |
#. type: Plain text |
| 2540 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2541 |
#: opensuse-tumbleweed |
| 2542 |
msgid "" |
| 2543 |
"\\&CW<*foo{IO}> is an alternative to the CW<*HANDLE> mechanism given in " |
| 2544 |
"\"Typeglobs and Filehandles\" in perldata for passing filehandles into or " |
| 2545 |
"out of subroutines, or storing into larger data structures. Its " |
| 2546 |
"disadvantage is that it won\\*(Aqt create a new filehandle for you. Its " |
| 2547 |
"advantage is that you have less risk of clobbering more than you want to " |
| 2548 |
"with a typeglob assignment. (It still conflates file and directory handles, " |
| 2549 |
"though.) However, if you assign the incoming value to a scalar instead of a " |
| 2550 |
"typeglob as we do in the examples below, there\\*(Aqs no risk of that " |
| 2551 |
"happening." |
| 2552 |
msgstr "" |
| 2553 |
|
| 2554 |
#. type: Plain text |
| 2555 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2556 |
#: opensuse-tumbleweed |
| 2557 |
msgid "" |
| 2558 |
"That\\*(Aqs it for creating references. By now you\\*(Aqre probably dying " |
| 2559 |
"to know how to use references to get back to your long-lost data. There are " |
| 2560 |
"several basic methods." |
| 2561 |
msgstr "" |
| 2562 |
|
| 2563 |
#. type: Plain text |
| 2564 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2565 |
#: opensuse-tumbleweed |
| 2566 |
msgid "" |
| 2567 |
"Anywhere you\\*(Aqd put an identifier (or chain of identifiers) as part of a " |
| 2568 |
"variable or subroutine name, you can replace the identifier with a simple " |
| 2569 |
"scalar variable containing a reference of the correct type:" |
| 2570 |
msgstr "" |
| 2571 |
|
| 2572 |
#. type: Plain text |
| 2573 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2574 |
#: opensuse-tumbleweed |
| 2575 |
msgid "" |
| 2576 |
"It\\*(Aqs important to understand that we are specifically I<not> " |
| 2577 |
"dereferencing \\&CW<$arrayref[0]> or CW<$hashref{\"KEY\"}> there. The " |
| 2578 |
"dereference of the scalar variable happens I<before> it does any key " |
| 2579 |
"lookups. Anything more complicated than a simple scalar variable must use " |
| 2580 |
"methods 2 or 3 below. However, a \"simple scalar\" includes an identifier " |
| 2581 |
"that itself uses method 1 recursively. Therefore, the following prints " |
| 2582 |
"\"howdy\"." |
| 2583 |
msgstr "" |
| 2584 |
|
| 2585 |
#. type: Plain text |
| 2586 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2587 |
#: opensuse-tumbleweed |
| 2588 |
msgid "" |
| 2589 |
"Anywhere you\\*(Aqd put an identifier (or chain of identifiers) as part of a " |
| 2590 |
"variable or subroutine name, you can replace the identifier with a BLOCK " |
| 2591 |
"returning a reference of the correct type. In other words, the previous " |
| 2592 |
"examples could be written like this:" |
| 2593 |
msgstr "" |
| 2594 |
|
| 2595 |
#. type: Plain text |
| 2596 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2597 |
#: opensuse-tumbleweed |
| 2598 |
msgid "" |
| 2599 |
"Admittedly, it\\*(Aqs a little silly to use the curlies in this case, but " |
| 2600 |
"the BLOCK can contain any arbitrary expression, in particular, subscripted " |
| 2601 |
"expressions:" |
| 2602 |
msgstr "" |
| 2603 |
|
| 2604 |
#. type: Plain text |
| 2605 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2606 |
#: opensuse-tumbleweed |
| 2607 |
msgid "" |
| 2608 |
"Because of being able to omit the curlies for the simple case of CW<$$x>, " |
| 2609 |
"people often make the mistake of viewing the dereferencing symbols as proper " |
| 2610 |
"operators, and wonder about their precedence. If they were, though, you " |
| 2611 |
"could use parentheses instead of braces. That\\*(Aqs not the case. " |
| 2612 |
"Consider the difference below; case 0 is a short-hand version of case 1, " |
| 2613 |
"\\&I<not> case 2:" |
| 2614 |
msgstr "" |
| 2615 |
|
| 2616 |
#. type: Plain text |
| 2617 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2618 |
#: opensuse-tumbleweed |
| 2619 |
msgid "" |
| 2620 |
"Case 2 is also deceptive in that you\\*(Aqre accessing a variable called " |
| 2621 |
"CW<%hashref>, not dereferencing through CW<$hashref> to the hash it\\*(Aqs " |
| 2622 |
"presumably referencing. That would be case 3." |
| 2623 |
msgstr "" |
| 2624 |
|
| 2625 |
#. type: Plain text |
| 2626 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2627 |
#: opensuse-tumbleweed |
| 2628 |
msgid "" |
| 2629 |
"This is one of the cases we mentioned earlier in which references could " |
| 2630 |
"spring into existence when in an lvalue context. Before this statement, " |
| 2631 |
"CW<$array[$x]> may have been undefined. If so, it\\*(Aqs automatically " |
| 2632 |
"defined with a hash reference so that we can look up \\&CW<\\*(C`{\"foo\"}" |
| 2633 |
"\\*(C'> in it. Likewise CW<\\*(C`$array[$x]-E<gt>{\"foo\"}\\*(C'> will " |
| 2634 |
"automatically get defined with an array reference so that we can look up " |
| 2635 |
"CW<\\*(C`[0]\\*(C'> in it. This process is called I<autovivification>." |
| 2636 |
msgstr "" |
| 2637 |
|
| 2638 |
#. type: Plain text |
| 2639 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2640 |
#: opensuse-tumbleweed |
| 2641 |
msgid "" |
| 2642 |
"Which, in the degenerate case of using only ordinary arrays, gives you " |
| 2643 |
"multidimensional arrays just like C\\*(Aqs:" |
| 2644 |
msgstr "" |
| 2645 |
|
| 2646 |
#. type: Plain text |
| 2647 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2648 |
#: opensuse-tumbleweed |
| 2649 |
msgid "" |
| 2650 |
"Well, okay, not entirely like C\\*(Aqs arrays, actually. C doesn\\*(Aqt " |
| 2651 |
"know how to grow its arrays on demand. Perl does." |
| 2652 |
msgstr "" |
| 2653 |
|
| 2654 |
#. type: Plain text |
| 2655 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2656 |
#: opensuse-tumbleweed |
| 2657 |
msgid "" |
| 2658 |
"If a reference happens to be a reference to an object, then there are " |
| 2659 |
"probably methods to access the things referred to, and you should probably " |
| 2660 |
"stick to those methods unless you\\*(Aqre in the class package that defines " |
| 2661 |
"the object\\*(Aqs methods. In other words, be nice, and don\\*(Aqt violate " |
| 2662 |
"the object\\*(Aqs encapsulation without a very good reason. Perl does not " |
| 2663 |
"enforce encapsulation. We are not totalitarians here. We do expect some " |
| 2664 |
"basic civility though." |
| 2665 |
msgstr "" |
| 2666 |
|
| 2667 |
#. type: Plain text |
| 2668 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2669 |
#: opensuse-tumbleweed |
| 2670 |
msgid "" |
| 2671 |
"Using a reference as a string produces both its referent\\*(Aqs type, " |
| 2672 |
"including any package blessing as described in perlobj, as well as the " |
| 2673 |
"numeric address expressed in hex. The B<ref()> operator returns just the " |
| 2674 |
"type of thing the reference is pointing to, without the address. See " |
| 2675 |
"\"ref\" in perlfunc for details and examples of its use." |
| 2676 |
msgstr "" |
| 2677 |
|
| 2678 |
#. type: Plain text |
| 2679 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2680 |
#: opensuse-tumbleweed |
| 2681 |
msgid "Here\\*(Aqs a trick for interpolating a subroutine call into a string:" |
| 2682 |
msgstr "" |
| 2683 |
|
| 2684 |
#. type: Plain text |
| 2685 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2686 |
#: opensuse-tumbleweed |
| 2687 |
msgid "" |
| 2688 |
"The way it works is that when the CW<\\*(C`@{...}\\*(C'> is seen in the " |
| 2689 |
"double-quoted string, it\\*(Aqs evaluated as a block. The block creates a " |
| 2690 |
"reference to an anonymous array containing the results of the call to " |
| 2691 |
"CW<\\*(C`mysub(1,2,3)\\*(C'>. So the whole block returns a reference to an " |
| 2692 |
"array, which is then dereferenced by CW<\\*(C`@{...}\\*(C'> and stuck into " |
| 2693 |
"the double-quoted string. This chicanery is also useful for arbitrary " |
| 2694 |
"expressions:" |
| 2695 |
msgstr "" |
| 2696 |
|
| 2697 |
#. type: Plain text |
| 2698 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2699 |
#: opensuse-tumbleweed |
| 2700 |
msgid "" |
| 2701 |
"Because objects in Perl are implemented as references, it\\*(Aqs possible to " |
| 2702 |
"have circular references with objects as well. Imagine a TreeNode class " |
| 2703 |
"where each node references its parent and child nodes. Any node with a " |
| 2704 |
"parent will be part of a circular reference." |
| 2705 |
msgstr "" |
| 2706 |
|
| 2707 |
#. type: Plain text |
| 2708 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2709 |
#: opensuse-tumbleweed |
| 2710 |
msgid "Here\\*(Aqs how we can make the first example safer:" |
| 2711 |
msgstr "" |
| 2712 |
|
| 2713 |
#. type: Plain text |
| 2714 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2715 |
#: opensuse-tumbleweed |
| 2716 |
msgid "" |
| 2717 |
"We said that references spring into existence as necessary if they are " |
| 2718 |
"undefined, but we didn\\*(Aqt say what happens if a value used as a " |
| 2719 |
"reference is already defined, but I<isn\\*(Aqt> a hard reference. If you " |
| 2720 |
"use it as a reference, it\\*(Aqll be treated as a symbolic reference. That " |
| 2721 |
"is, the value of the scalar is taken to be the I<name> of a variable, rather " |
| 2722 |
"than a direct link to a (possibly) anonymous value." |
| 2723 |
msgstr "" |
| 2724 |
|
| 2725 |
#. type: Plain text |
| 2726 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2727 |
#: opensuse-tumbleweed |
| 2728 |
msgid "" |
| 2729 |
"This is powerful, and slightly dangerous, in that it\\*(Aqs possible to " |
| 2730 |
"intend (with the utmost sincerity) to use a hard reference, and accidentally " |
| 2731 |
"use a symbolic reference instead. To protect against that, you can say" |
| 2732 |
msgstr "" |
| 2733 |
|
| 2734 |
#. type: Plain text |
| 2735 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2736 |
#: opensuse-tumbleweed |
| 2737 |
msgid "" |
| 2738 |
"Only package variables (globals, even if localized) are visible to symbolic " |
| 2739 |
"references. Lexical variables (declared with B<my()>) aren\\*(Aqt in a " |
| 2740 |
"symbol table, and thus are invisible to this mechanism. For example:" |
| 2741 |
msgstr "" |
| 2742 |
|
| 2743 |
#. type: Plain text |
| 2744 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2745 |
#: opensuse-tumbleweed |
| 2746 |
msgid "" |
| 2747 |
"will have the same effect. This construct is I<not> considered to be a " |
| 2748 |
"symbolic reference when you\\*(Aqre using strict refs:" |
| 2749 |
msgstr "" |
| 2750 |
|
| 2751 |
#. type: Plain text |
| 2752 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2753 |
#: opensuse-tumbleweed |
| 2754 |
msgid "" |
| 2755 |
"Pseudo-hashes have been removed from Perl. The fields pragma remains " |
| 2756 |
"available." |
| 2757 |
msgstr "" |
| 2758 |
|
| 2759 |
#. type: Plain text |
| 2760 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2761 |
#: opensuse-tumbleweed |
| 2762 |
msgid "" |
| 2763 |
"As explained above, an anonymous function with access to the lexical " |
| 2764 |
"variables visible when that function was compiled, creates a closure. It " |
| 2765 |
"retains access to those variables even though it doesn\\*(Aqt get run until " |
| 2766 |
"later, such as in a signal handler or a Tk callback." |
| 2767 |
msgstr "" |
| 2768 |
|
| 2769 |
#. type: Plain text |
| 2770 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2771 |
#: opensuse-tumbleweed |
| 2772 |
msgid "" |
| 2773 |
"The B<red()> and B<green()> functions would be similar. To create these, " |
| 2774 |
"we\\*(Aqll assign a closure to a typeglob of the name of the function " |
| 2775 |
"we\\*(Aqre trying to build." |
| 2776 |
msgstr "" |
| 2777 |
|
| 2778 |
#. type: Plain text |
| 2779 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2780 |
#: opensuse-tumbleweed |
| 2781 |
msgid "" |
| 2782 |
"Now all those different functions appear to exist independently. You can " |
| 2783 |
"call B<red()>, B<RED()>, B<blue()>, B<BLUE()>, B<green()>, etc. This " |
| 2784 |
"technique saves on both compile time and memory use, and is less error-prone " |
| 2785 |
"as well, since syntax checks happen at compile time. It\\*(Aqs critical " |
| 2786 |
"that any variables in the anonymous subroutine be lexicals in order to " |
| 2787 |
"create a proper closure. That\\*(Aqs the reasons for the CW<\\*(C`my\\*(C'> " |
| 2788 |
"on the loop iteration variable." |
| 2789 |
msgstr "" |
| 2790 |
|
| 2791 |
#. type: Plain text |
| 2792 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2793 |
#: opensuse-tumbleweed |
| 2794 |
msgid "" |
| 2795 |
"Anonymous subroutines get to capture each time you execute the " |
| 2796 |
"CW<\\*(C`sub\\*(C'> operator, as they are created on the fly. If you are " |
| 2797 |
"accustomed to using nested subroutines in other programming languages with " |
| 2798 |
"their own private variables, you\\*(Aqll have to work at it a bit in Perl. " |
| 2799 |
"The intuitive coding of this type of thing incurs mysterious warnings about " |
| 2800 |
"\"will not stay shared\" due to the reasons explained above. For example, " |
| 2801 |
"this won\\*(Aqt work:" |
| 2802 |
msgstr "" |
| 2803 |
|
| 2804 |
#. type: Plain text |
| 2805 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2806 |
#: opensuse-tumbleweed |
| 2807 |
#, no-wrap |
| 2808 |
msgid "" |
| 2809 |
"\\& $r = \\e@a;\n" |
| 2810 |
"\\& @b = $r-E<gt>@*; # equivalent to @$r or @{ $r }\n" |
| 2811 |
"\\&\n" |
| 2812 |
"\\& $r = [ 1, [ 2, 3 ], 4 ];\n" |
| 2813 |
"\\& $r-E<gt>[1]-E<gt>@*; # equivalent to @{ $r-E<gt>[1] }\n" |
| 2814 |
"\\&\n" |
| 2815 |
"\\& $aref-E<gt>@* = (1, 2, 3); # same as @{ $aref } = (1, 2, 3)\n" |
| 2816 |
msgstr "" |
| 2817 |
|
| 2818 |
#. type: SH |
| 2819 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2820 |
#: opensuse-tumbleweed |
| 2821 |
#, no-wrap |
| 2822 |
msgid "WARNING: Don\\*(Aqt use references as hash keys" |
| 2823 |
msgstr "" |
| 2824 |
|
| 2825 |
#. type: Plain text |
| 2826 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2827 |
#: opensuse-tumbleweed |
| 2828 |
msgid "" |
| 2829 |
"If you try to dereference the key, it won\\*(Aqt do a hard dereference, and " |
| 2830 |
"you won\\*(Aqt accomplish what you\\*(Aqre attempting. You might want to do " |
| 2831 |
"something more like" |
| 2832 |
msgstr "" |
| 2833 |
|
| 2834 |
#. type: Plain text |
| 2835 |
#: fedora-44 fedora-rawhide mageia-cauldron opensuse-leap-16-1 |
| 2836 |
#: opensuse-tumbleweed |
| 2837 |
msgid "" |
| 2838 |
"And then at least you can use the B<values()>, which will be real refs, " |
| 2839 |
"instead of the B<keys()>, which won\\*(Aqt." |
| 2840 |
msgstr "" |
| 2841 |
|
| 2842 |
#. type: TH |
| 2843 |
#: fedora-rawhide |
| 2844 |
#, no-wrap |
| 2845 |
msgid "2026-03-30" |
| 2846 |
msgstr "" |
| 2847 |
|
| 2848 |
#. type: TH |
| 2849 |
#: fedora-rawhide |
| 2850 |
#, no-wrap |
| 2851 |
msgid "perl v5.42.2" |
| 2852 |
msgstr "" |
| 2853 |
|
| 2854 |
#. type: TH |
| 2855 |
#: mageia-cauldron |
| 2856 |
#, no-wrap |
| 2857 |
msgid "2025-06-24" |
| 2858 |
msgstr "" |
| 2859 |
|
| 2860 |
#. type: TH |
| 2861 |
#: mageia-cauldron |
| 2862 |
#, no-wrap |
| 2863 |
msgid "perl v5.42.0" |
| 2864 |
msgstr "" |