{"id":397560,"date":"2024-06-29T13:31:35","date_gmt":"2024-06-29T13:31:35","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=397560"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=397560","title":{"rendered":"<span>\u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 Perl \u0447\u0435\u0440\u0435\u0437 local<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 <strong>perl<\/strong> \u0435\u0441\u0442\u044c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 <strong>local<\/strong>. \u041e\u043d\u043e \u043f\u043e\u0434\u043c\u0435\u043d\u044f\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <strong>undef<\/strong>-\u043e\u043c \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0431\u043b\u043e\u043a\u0430. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u0445\u0435\u0448\u0438, \u043c\u0430\u0441\u0441\u0438\u0432\u044b \u0438 \u0441\u043a\u0430\u043b\u044f\u0440\u044b, \u0430 \u0442\u0430\u043a \u0436\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u043b\u0438 \u0441\u0440\u0435\u0437\u044b \u0445\u0435\u0448\u0435\u0439 \u0438 \u0441\u043a\u0430\u043b\u044f\u0440\u043e\u0432.<\/p>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0445\u0435\u0448\u0438 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 <strong>local<\/strong> \u043d\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442.<\/p>\n<p>\u041f\u043e\u0434 \u0445\u0435\u0448\u0430\u043c\u0438 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u044f \u043f\u043e\u043d\u0438\u043c\u0430\u044e \u0445\u0435\u0448 \u0441 \u0434\u0432\u043e\u0435\u0442\u043e\u0447\u0438\u0435\u043c \u043d\u0430 \u043a\u043e\u043d\u0446\u0435 (<code>%\u041f\u0430\u043a\u0435\u0442::)<\/code> \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u043f\u0430\u043a\u0435\u0442\u0430 (GLOB).<\/p>\n<pre><code class=\"perl\">package A {   sub fn {}   $x = 10;   @x = qw(1 2); }  use DDP; p %A::  # -> {         #    fn   *A::fn  (layers: ),         #    x    *A::x  (layers: )         # }<\/code><\/pre>\n<p>\u0422\u0443\u0442 <code>@x<\/code> \u0438 <code>$x<\/code> \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c \u0433\u043b\u043e\u0431\u0435 &#8212; <code>*A::x<\/code>.<\/p>\n<p>\u0414\u043e\u0441\u0442\u0443\u043f \u043a \u043d\u0438\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"perl\">package A { sub fn {} $x = 10; @x = qw(1 2); }  $\\ = \"\\n\"; $, = \", \";  print $A::x, ${ *A::x{SCALAR} }, ${ *{ $A::{x} }{SCALAR} };  # -> 10, 10, 10 print @A::x, @{ *A::x{ARRAY} }, @{ *{ $A::{x} }{ARRAY} };  # -> 1, 2, 1, 2, 1, 2<\/code><\/pre>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c \u0432\u043d\u0430\u0447\u0430\u043b\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c GLOB \u0438\u0437 \u0445\u0435\u0448\u0430 \u043f\u0430\u043a\u0435\u0442\u0430 (<code>$A::{x}<\/code>), \u0440\u0430\u0437\u044b\u043c\u0435\u043d\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u0435\u0433\u043e (<code>*{ $A::{x} }<\/code>), \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0441\u043a\u0430\u043b\u044f\u0440 (<code>*{ $A::{x} }{SCALAR}<\/code>) \u0438, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0440\u0430\u0437\u044b\u043c\u0435\u043d\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u0441\u043a\u0430\u043b\u044f\u0440 (<code>${ *{ $A::{x} }{SCALAR} }<\/code>).<\/p>\n<p>GLOB \u0436\u0435 \u044d\u0442\u043e \u0442\u0430\u043a\u043e\u0439 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0445\u0435\u0448 \u0441 \u043f\u0440\u0435\u0434\u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u043a\u043b\u044e\u0447\u0430\u043c\u0438: SCALAR, ARRAY, HASH, CODE, REF, GLOB, LVALUE, FORMAT, IO, VSTRING.<\/p>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043d\u0438\u0445 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c\u0443 \u0442\u0438\u043f\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u0441\u0438\u043c\u0432\u043e\u043b\u0435 (fn \u0438 x &#8212; \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0432 \u043f\u0430\u043a\u0435\u0442\u0435 A).<\/p>\n<p>\u041d\u043e \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a <strong>local<\/strong>.<\/p>\n<pre><code class=\"perl\">use DDP; our %x = qw\/a b d c\/; { local %x;  $x{a} = \"R\"; p %x;  # -> {          #    a   \"R\"          # } } p %x;  # -> {        #    a   \"b\"        #    d   \"c\"        # }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c <strong>local<\/strong> \u043f\u043e\u0434\u043c\u0435\u043d\u0438\u043b\u0430 <code>our %x<\/code> \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0431\u043b\u043e\u043a\u0430.<\/p>\n<p>\u0421 <code>my %x<\/code> <strong>local<\/strong> \u043e\u0442\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c (\u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435):<\/p>\n<pre><code class=\"perl\">@@\u0444\u0430\u0439\u043b x.pl: my %x = qw\/a b\/; { local %x;   p %x; }  @@\u043a\u043e\u043d\u0441\u043e\u043b\u044c: $ perl x.pl Can't localize lexical variable %x at x.pl line 13.<\/code><\/pre>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u0430\u043c\u043e\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435: \u043d\u0430 \u0445\u0435\u0448 \u043f\u0430\u043a\u0435\u0442\u0430 <strong>local<\/strong> \u043d\u0435 \u0440\u0443\u0433\u0430\u0435\u0442\u0441\u044f, \u043d\u043e \u0438 \u043d\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0435\u0433\u043e: <\/p>\n<pre><code class=\"perl\">package A { sub fn { 10 } $x = 20; }  { local %A::;  *A::fn = sub {6}; $A::x = 3;  print &amp;A::fn;  # -> 6 print $A::x; # -> 3 }  print &amp;A::fn;  # -> 6 print $A::x;   # -> 3<\/code><\/pre>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c <code>$A::x<\/code>  \u0438  <code>A::fn<\/code> \u043d\u0435 \u0432\u0435\u0440\u043d\u0443\u043b\u0438\u0441\u044c \u043a \u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044e.<\/p>\n<p>\u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0435\u0441\u043b\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u043d\u0435 \u0445\u0435\u0448 <code>%A::<\/code>, \u0430 \u0441\u0440\u0435\u0437 \u0432\u0441\u0435\u0445 \u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0435\u0439 (@A::{keys %A::}), \u0442\u043e <strong>local<\/strong> \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442:<\/p>\n<pre><code class=\"perl\">package A { sub fn { 10 } $x = 20; }  { local @A::{keys %A::};  *A::fn = sub {6}; $A::x = 3;  print &amp;A::fn;  # -> 6 print $A::x; # -> 3 }  print &amp;A::fn;    # 10 print $A::x;     # 20<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0438 \u0435\u0449\u0451 \u043e\u0434\u043d\u0430 \u0442\u0430\u0439\u043d\u0430 <strong>perl<\/strong>-\u0430 \u0440\u0430\u0441\u043a\u0440\u044b\u0442\u0430!<\/p>\n<p>\u0425\u043e\u0442\u044f \u043d\u0435 \u0434\u043e \u043a\u043e\u043d\u0446\u0430. \u0415\u0441\u043b\u0438 \u0443 \u043a\u043e\u0433\u043e-\u0442\u043e \u0435\u0441\u0442\u044c \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u0442\u0430\u043a\u043e\u043c\u0443 \u0441\u0442\u0440\u0430\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044e <strong>local<\/strong> c \u0445\u0435\u0448\u0435\u043c \u043f\u0430\u043a\u0435\u0442\u0430, \u0442\u043e \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0435\u0433\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445.<\/p>\n<p>\u041d\u0443 \u0438 \u043d\u0430\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043f\u043e\u043b\u044e\u0431\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u044b\u043c \u043f\u0430\u043a\u0435\u0442\u0430 <strong>main<\/strong>:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/048\/90a\/b84\/04890ab84234d91eaac762a8756f6a95.png\" width=\"620\" height=\"617\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/048\/90a\/b84\/04890ab84234d91eaac762a8756f6a95.png\"\/><figcaption><\/figcaption><\/figure>\n<p> \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043d\u0430\u0448 \u043f\u0430\u043a\u0435\u0442 <strong>A<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 <strong>main::A<\/strong>.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/667\/591\/f36\/667591f3699466db57862b9da5b18df7.png\" width=\"683\" height=\"833\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/667\/591\/f36\/667591f3699466db57862b9da5b18df7.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u043a\u0435\u0442\u044b \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043f\u0430\u043a\u0435\u0442\u0435 main, \u0430 \u043f\u0430\u043a\u0435\u0442\u044b \u0441 \u0447\u0435\u0442\u0432\u0435\u0440\u043e\u0442\u043e\u0447\u0438\u044f\u043c\u0438 \u0443\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u043d\u0438\u0445 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0431\u0440\u0430\u0437\u0443\u044f \u0434\u0440\u0435\u0432\u043e\u0432\u0438\u0434\u043d\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443:<\/p>\n<pre><code class=\"perl\">package A { sub fn { 10 } $x = 20; }  package A::A { $x = 30; }  # ->  #  %main:: #    A::   *main::A #      fn    *A::fn #      x     *A::x #      A::   *A::A:: #        x     *A::A::x  print \\%main::A == \\%A? \"\u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435\": \"\u0440\u0430\u0437\u043d\u043e\u0435\"; # -> \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435 print $main::{A::}{A::} == $A::A::? \"\u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435\": \"\u0440\u0430\u0437\u043d\u043e\u0435\"; # -> \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0438 \u0432\u0441\u0451. \u041e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0436\u0435\u043b\u0430\u0442\u044c \u043d\u0430\u043c \u0432\u0441\u0435\u043c \u043e\u0442\u043b\u0438\u0447\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f!<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/585038\/\"> https:\/\/habr.com\/ru\/articles\/585038\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 <strong>perl<\/strong> \u0435\u0441\u0442\u044c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 <strong>local<\/strong>. \u041e\u043d\u043e \u043f\u043e\u0434\u043c\u0435\u043d\u044f\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <strong>undef<\/strong>-\u043e\u043c \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0431\u043b\u043e\u043a\u0430. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u0445\u0435\u0448\u0438, \u043c\u0430\u0441\u0441\u0438\u0432\u044b \u0438 \u0441\u043a\u0430\u043b\u044f\u0440\u044b, \u0430 \u0442\u0430\u043a \u0436\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u043b\u0438 \u0441\u0440\u0435\u0437\u044b \u0445\u0435\u0448\u0435\u0439 \u0438 \u0441\u043a\u0430\u043b\u044f\u0440\u043e\u0432.<\/p>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0445\u0435\u0448\u0438 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 <strong>local<\/strong> \u043d\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442.<\/p>\n<p>\u041f\u043e\u0434 \u0445\u0435\u0448\u0430\u043c\u0438 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u044f \u043f\u043e\u043d\u0438\u043c\u0430\u044e \u0445\u0435\u0448 \u0441 \u0434\u0432\u043e\u0435\u0442\u043e\u0447\u0438\u0435\u043c \u043d\u0430 \u043a\u043e\u043d\u0446\u0435 (<code>%\u041f\u0430\u043a\u0435\u0442::)<\/code> \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u043f\u0430\u043a\u0435\u0442\u0430 (GLOB).<\/p>\n<pre><code class=\"perl\">package A {   sub fn {}   $x = 10;   @x = qw(1 2); }  use DDP; p %A::  # -> {         #    fn   *A::fn  (layers: ),         #    x    *A::x  (layers: )         # }<\/code><\/pre>\n<p>\u0422\u0443\u0442 <code>@x<\/code> \u0438 <code>$x<\/code> \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c \u0433\u043b\u043e\u0431\u0435 &#8212; <code>*A::x<\/code>.<\/p>\n<p>\u0414\u043e\u0441\u0442\u0443\u043f \u043a \u043d\u0438\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"perl\">package A { sub fn {} $x = 10; @x = qw(1 2); }  $\\ = \"\\n\"; $, = \", \";  print $A::x, ${ *A::x{SCALAR} }, ${ *{ $A::{x} }{SCALAR} };  # -> 10, 10, 10 print @A::x, @{ *A::x{ARRAY} }, @{ *{ $A::{x} }{ARRAY} };  # -> 1, 2, 1, 2, 1, 2<\/code><\/pre>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c \u0432\u043d\u0430\u0447\u0430\u043b\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c GLOB \u0438\u0437 \u0445\u0435\u0448\u0430 \u043f\u0430\u043a\u0435\u0442\u0430 (<code>$A::{x}<\/code>), \u0440\u0430\u0437\u044b\u043c\u0435\u043d\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u0435\u0433\u043e (<code>*{ $A::{x} }<\/code>), \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0441\u043a\u0430\u043b\u044f\u0440 (<code>*{ $A::{x} }{SCALAR}<\/code>) \u0438, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0440\u0430\u0437\u044b\u043c\u0435\u043d\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u0441\u043a\u0430\u043b\u044f\u0440 (<code>${ *{ $A::{x} }{SCALAR} }<\/code>).<\/p>\n<p>GLOB \u0436\u0435 \u044d\u0442\u043e \u0442\u0430\u043a\u043e\u0439 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0445\u0435\u0448 \u0441 \u043f\u0440\u0435\u0434\u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u043a\u043b\u044e\u0447\u0430\u043c\u0438: SCALAR, ARRAY, HASH, CODE, REF, GLOB, LVALUE, FORMAT, IO, VSTRING.<\/p>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043d\u0438\u0445 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c\u0443 \u0442\u0438\u043f\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u0441\u0438\u043c\u0432\u043e\u043b\u0435 (fn \u0438 x &#8212; \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0432 \u043f\u0430\u043a\u0435\u0442\u0435 A).<\/p>\n<p>\u041d\u043e \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a <strong>local<\/strong>.<\/p>\n<pre><code class=\"perl\">use DDP; our %x = qw\/a b d c\/; { local %x;  $x{a} = \"R\"; p %x;  # -> {          #    a   \"R\"          # } } p %x;  # -> {        #    a   \"b\"        #    d   \"c\"        # }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c <strong>local<\/strong> \u043f\u043e\u0434\u043c\u0435\u043d\u0438\u043b\u0430 <code>our %x<\/code> \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0431\u043b\u043e\u043a\u0430.<\/p>\n<p>\u0421 <code>my %x<\/code> <strong>local<\/strong> \u043e\u0442\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c (\u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435):<\/p>\n<pre><code class=\"perl\">@@\u0444\u0430\u0439\u043b x.pl: my %x = qw\/a b\/; { local %x;   p %x; }  @@\u043a\u043e\u043d\u0441\u043e\u043b\u044c: $ perl x.pl Can't localize lexical variable %x at x.pl line 13.<\/code><\/pre>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u0430\u043c\u043e\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435: \u043d\u0430 \u0445\u0435\u0448 \u043f\u0430\u043a\u0435\u0442\u0430 <strong>local<\/strong> \u043d\u0435 \u0440\u0443\u0433\u0430\u0435\u0442\u0441\u044f, \u043d\u043e \u0438 \u043d\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0435\u0433\u043e: <\/p>\n<pre><code class=\"perl\">package A { sub fn { 10 } $x = 20; }  { local %A::;  *A::fn = sub {6}; $A::x = 3;  print &amp;A::fn;  # -> 6 print $A::x; # -> 3 }  print &amp;A::fn;  # -> 6 print $A::x;   # -> 3<\/code><\/pre>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c <code>$A::x<\/code>  \u0438  <code>A::fn<\/code> \u043d\u0435 \u0432\u0435\u0440\u043d\u0443\u043b\u0438\u0441\u044c \u043a \u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044e.<\/p>\n<p>\u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0435\u0441\u043b\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u043d\u0435 \u0445\u0435\u0448 <code>%A::<\/code>, \u0430 \u0441\u0440\u0435\u0437 \u0432\u0441\u0435\u0445 \u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0435\u0439 (@A::{keys %A::}), \u0442\u043e <strong>local<\/strong> \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442:<\/p>\n<pre><code class=\"perl\">package A { sub fn { 10 } $x = 20; }  { local @A::{keys %A::};  *A::fn = sub {6}; $A::x = 3;  print &amp;A::fn;  # -> 6 print $A::x; # -> 3 }  print &amp;A::fn;    # 10 print $A::x;     # 20<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0438 \u0435\u0449\u0451 \u043e\u0434\u043d\u0430 \u0442\u0430\u0439\u043d\u0430 <strong>perl<\/strong>-\u0430 \u0440\u0430\u0441\u043a\u0440\u044b\u0442\u0430!<\/p>\n<p>\u0425\u043e\u0442\u044f \u043d\u0435 \u0434\u043e \u043a\u043e\u043d\u0446\u0430. \u0415\u0441\u043b\u0438 \u0443 \u043a\u043e\u0433\u043e-\u0442\u043e \u0435\u0441\u0442\u044c \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u0442\u0430\u043a\u043e\u043c\u0443 \u0441\u0442\u0440\u0430\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044e <strong>local<\/strong> c \u0445\u0435\u0448\u0435\u043c \u043f\u0430\u043a\u0435\u0442\u0430, \u0442\u043e \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0435\u0433\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445.<\/p>\n<p>\u041d\u0443 \u0438 \u043d\u0430\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043f\u043e\u043b\u044e\u0431\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u044b\u043c \u043f\u0430\u043a\u0435\u0442\u0430 <strong>main<\/strong>:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p> \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043d\u0430\u0448 \u043f\u0430\u043a\u0435\u0442 <strong>A<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 <strong>main::A<\/strong>.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u043a\u0435\u0442\u044b \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043f\u0430\u043a\u0435\u0442\u0435 main, \u0430 \u043f\u0430\u043a\u0435\u0442\u044b \u0441 \u0447\u0435\u0442\u0432\u0435\u0440\u043e\u0442\u043e\u0447\u0438\u044f\u043c\u0438 \u0443\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u043d\u0438\u0445 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0431\u0440\u0430\u0437\u0443\u044f \u0434\u0440\u0435\u0432\u043e\u0432\u0438\u0434\u043d\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443:<\/p>\n<pre><code class=\"perl\">package A { sub fn { 10 } $x = 20; }  package A::A { $x = 30; }  # ->  #  %main:: #    A::   *main::A #      fn    *A::fn #      x     *A::x #      A::   *A::A:: #        x     *A::A::x  print \\%main::A == \\%A? \"\u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435\": \"\u0440\u0430\u0437\u043d\u043e\u0435\"; # -> \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435 print $main::{A::}{A::} == $A::A::? \"\u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435\": \"\u0440\u0430\u0437\u043d\u043e\u0435\"; # -> \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0438 \u0432\u0441\u0451. \u041e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0436\u0435\u043b\u0430\u0442\u044c \u043d\u0430\u043c \u0432\u0441\u0435\u043c \u043e\u0442\u043b\u0438\u0447\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f!<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/585038\/\"> https:\/\/habr.com\/ru\/articles\/585038\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-397560","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/397560","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=397560"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/397560\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=397560"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=397560"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=397560"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}