Skip to content
Open
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update perlsecret.ru.pod
  • Loading branch information
mishin committed Oct 18, 2014
commit be13cf682e9469156de98741b3ff6e625b616d9b
33 changes: 14 additions & 19 deletions lib/perlsecret.ru.pod
Original file line number Diff line number Diff line change
Expand Up @@ -433,38 +433,33 @@ https://ru.wikipedia.org/wiki/Дополнительный_код_(предст
В некоторых случаях полный гоатсе не нужен, потому что нет необходимости
для хранения значения в переменной. Побочный эффект списочного присвоения в
скалярные контексте может быть получен I<правостороннем гоатсе> (C<()=>)
используется в скалярных контексте некоторых других значит чем assignement
к скалярным значением.
используемый в скалярных контексте имеет другое значение, чем присвоение
скаляру.
Например:
In some cases, the full goaste is not needed, because there is no need
to store the value in a variable. The side-effect of list assignment in
scalar context can be obtained with a I<right-handed goaste> (C<()=>)
used in a scalar context provided by some other mean than assignement
to a scalar.
For example:

# remove empty array refs

# удаление пустых ссылок на массивы
@arrays = ( [], [1], [ 1, 2 ], [], [ 5 .. 9 ] );

# @filled = ( [1], [ 1, 2 ], [ 5 .. 9 ] );
@filled = grep +()= @$_, @arrays;

(The C<+> is in the above line is a no-op, used to tell C<grep> that the
parentheses are not enclosing its arguments.)
(C<+> в строке выше не операция, используется, что сказать C<grep>,
что скобки не включают его аргументы.)

Here's a convoluted example where C<=()=> seems to be the proper
construct to use, but it's actually another secret operator that
really does the trick.
Вот запутанный пример, где C<=()=> , представляется, как соответствующей
конструкцией для использования, но это на самом деле еще один секретный оператор,
в действительности это трюк.

Imagine you want to know in how many elements C<< split() >> would split
a string, but do not care about the elements themselves. Using C<split()>
in scalar context:
Представьте, что вы хотите знать, на сколько элементов C<< split() >> разобьет
строку, но не заботится о самих элементах. Используйте C<< split() >>
в скалярных контексте:

my $count = split /:/, $string;

Gives the correct answer, but also a warning:
Дает правильный ответ, но и предупреждение:

Use of implicit split to @_ is deprecated
Использование неявного сплита для @_ не рекомендуется

Using C<=()=> to force scalar context on the left side (to get the number
of substrings) and list context on the right side (to avoid the deprecated
Expand Down