nataraj: (Default)
Swami Dhyan Nataraj ([personal profile] nataraj) wrote2007-06-16 12:53 pm

Вопрос по перлу

Хочу создать строку из N пробелов. Можно ли это сделать эффективнее чем в цикле добавлять по пробелу? (сишную вставку писать не хочу) Может быть есть готовая функция? ;-)

[identity profile] maravan.livejournal.com 2007-06-16 09:01 am (UTC)(link)
#!perl -w
use strict;

my $n = 50;
my $spaces = ' ' x $n;
ext_613079: Default userpic (Default)

[identity profile] shaplov.livejournal.com 2007-06-16 09:23 am (UTC)(link)
О! Работает!
А в каком месте об этом можно почитать?
vitus_wagner: My photo 2005 (Default)

[personal profile] vitus_wagner 2007-06-16 09:40 am (UTC)(link)
Коля, может тебе Camel book бумажную почитать дать?
ext_613079: Default userpic (Default)

[identity profile] shaplov.livejournal.com 2007-06-16 09:50 am (UTC)(link)
;-)
В свое время Белявский каждый второй мой вопрос встречал словами "Коля, купис себе Вюрблюда"

Проблема в том, что я его последовательно читать не смогу, а для ряда задач, для которых поисковая фраза неочивидна, так же и не очевиден и метод поиска в Вюрблюде... :-/

Поэтому увы, время от времени у меня возникают такие странные воросы. Слава богу что сейчас очень редко ;-)

[identity profile] maravan.livejournal.com 2007-06-16 10:20 am (UTC)(link)
Купи тогда perl cookbook (я уж не помню, что там за зверюга).
ext_613079: Default userpic (Default)

[identity profile] shaplov.livejournal.com 2007-06-16 10:23 am (UTC)(link)
Там баран...

Я ее не только купил, но и попытался почитать... В течении страницы читал рассуждения американского автора на тему, как его жена готовит русский борщ и не кладет в него при этом свеклы... А потом мне надоели, и я читать бросил ;-)

[identity profile] maravan.livejournal.com 2007-06-16 10:36 am (UTC)(link)
точно, баран..
а вот как раз её-то можно и не читать линейно :)

[identity profile] alexkuklin.livejournal.com 2007-06-16 01:40 pm (UTC)(link)
man perlop, вообще-то

Multiplicative Operators

Binary ``*'' multiplies two numbers.

Binary ``/'' divides two numbers.

Binary ``%'' computes the modulus of two numbers. Given integer operands $a and $b: If $b is positive, then $a % $b is $a minus the largest multiple of $b that is not greater than $a. If $b is negative, then $a % $b is $a minus the smallest multiple of $b that is not less than $a (i.e. the result will be less than or equal to zero). Note that when use integer is in scope, ``%'' gives you direct access to the modulus operator as implemented by your C compiler. This operator is not as well defined for negative operands, but it will execute faster.

Binary ``x'' is the repetition operator. In scalar context or if the left operand is not enclosed in parentheses, it returns a string consisting of the left operand repeated the number of times specified by the right operand. In list context, if the left operand is enclosed in parentheses or is a list formed by qw/STRING/, it repeats the list. If the right operand is zero or negative, it returns an empty string or an empty list, depending on the context.


print '-' x 80; # print row of dashes
ext_613079: Default userpic (Default)

[identity profile] shaplov.livejournal.com 2007-06-16 09:24 am (UTC)(link)
Хотя, нет, вопрос глуп. Где читать -- понятно ;-)

[identity profile] maravan.livejournal.com 2007-06-16 09:35 am (UTC)(link)
"-Папа, как работает телевизор?
-RTFM!
-(грустно) man что? :)
lodin: A bearded hacker in a hat (Default)

[personal profile] lodin 2007-06-23 06:09 pm (UTC)(link)
Офигеть, а я специально функцию написал!

Правда, она еще разделитель вставлять умеет. (Надо было написать "?,?,?,?,?")

Ну да разделитель -- это тоже иксом реализуется.
ext_613079: Default userpic (Default)

[identity profile] shaplov.livejournal.com 2007-06-23 06:14 pm (UTC)(link)
Играю в "Что? Где? Когда?" в команде "Химера" (капитан sasha_danilenko).
Да... наши люди повсюду...
lodin: A bearded hacker in a hat (Default)

[personal profile] lodin 2007-06-25 06:41 am (UTC)(link)
Земля квадратная, встретимся за углом. ;)