Misha Verbitsky ([info]tiphareth) wrote,
@ 2002-11-18 05:16:00
Current mood: depressed
Current music:Gong

Range Operators
Я переписал ljsm.pl [info]ati таким образом, что
он сохраняет отдельный дневник (без комментариев),
и еще добавляет "n replies" в конец каждого сообщения.
Мой собственный дневник составил 4 мегабайта всего
(в старой версии было 17 мег).

Осталось накачать побольше дневников,
написать процедуру парсинга и склепать
из скачанного полноценную френд-ленту,
на память потомству.

Сегодня весь вечер читал документацию к
оператору .. излюбленному достойным [info]ati
и рыдал в голос. Ничего более запутанного
природа, кажется, не произвела. Вообще
Перл сродни России - грязь, куча непонятных
артефактов и никогда не знаешь, что
получится, пока не попробуешь.

Вот, в назидание потомству, описание ..
Трепещите.



Range Operators

Binary ".." is the range operator, which is really two different opera-
tors depending on the context. In list context, it returns an list of
values counting (up by ones) from the left value to the right value.
If the left value is greater than the right value then it returns the
empty array. The range operator is useful for writing "foreach
(1..10)" loops and for doing slice operations on arrays. In the current
implementation, no temporary array is created when the range operator
is used as the expression in "foreach" loops, but older versions of
Perl might burn a lot of memory when you write something like this:

for (1 .. 1_000_000) {
# code
}

The range operator also works on strings, using the magical auto-incre-
ment, see below.

In scalar context, ".." returns a boolean value. The operator is
bistable, like a flip-flop, and emulates the line-range (comma) opera-
tor of sed, awk, and various editors. Each ".." operator maintains its
own boolean state. It is false as long as its left operand is false.
Once the left operand is true, the range operator stays true until the
right operand is true, AFTER which the range operator becomes false
again. It doesn't become false till the next time the range operator
is evaluated. It can test the right operand and become false on the
same evaluation it became true (as in awk), but it still returns true
once. If you don't want it to test the right operand till the next
evaluation, as in sed, just use three dots ("...") instead of two. In
all other regards, "..." behaves just like ".." does.

The right operand is not evaluated while the operator is in the "false"
state, and the left operand is not evaluated while the operator is in
the "true" state. The precedence is a little lower than || and &&.
The value returned is either the empty string for false, or a sequence
number (beginning with 1) for true. The sequence number is reset for
each range encountered. The final sequence number in a range has the
string "E0" appended to it, which doesn't affect its numeric value, but
gives you something to search for if you want to exclude the endpoint.
You can exclude the beginning point by waiting for the sequence number
to be greater than 1. If either operand of scalar ".." is a constant
expression, that operand is implicitly compared to the $. variable, the
current line number.

Особенно трогательна, конечно, фраза
"The precedence is a little lower than || and &&."
Стилистика, медам и месье, стилистика.

Привет
Миша.



(Post a new comment)


[info]xyu
2002-11-17 21:13 (link)
странно а в кате по ссылке продолжения нихуя не смог залезть
заебал меня жежель скоро я его пошлю в хуй

(Reply to this)


[info]p_k
2002-11-17 23:50 (link)
Особенно трогательна, конечно, фраза
"The precedence is a little lower than || and &&."
Стилистика, медам и месье, стилистика.


Летает, но низенько-низенько... За это я Перл и люблю - за человечность.

(Reply to this)


[info]nofnord
2002-11-18 03:52 (link)
А в каком формате результат? А почему от комментов отказались?

(Reply to this) (Thread)


[info]tiphareth
2002-11-18 10:29 (link)

Результат в HTML (в том же формате, что
у [info]ati), но я как раз
пишу программу, которая делает
парсинг.

А отказался от комментариев, потому что
она работает слишком медленно -- т.е. скачать
мой дневник с комментариями заняло часов 10.
А я собираюсь дневников 100 скачать.
Причем у меня коннект сейчас T1, типа;
т.е. из России эта штука вообще работать
дня 3 будет.

Такие дела
Миша.

(Reply to this) (Parent) (Thread)


[info]nofnord
2002-11-19 00:33 (link)
В России и Украине есть провайдеры, которые могут выкачать за пару часов большой дневник ;)
Это не проблема.
Я бы просто рекомендовал дневник хранить не в HTML, а в XML.
Потом можно написать XSL какой пожелаешь и все будет выглядить нормально в современных броузерах (в том числе и под линукс, только нужно будет писать на самой старой трансформации).

Если есть желание, то можно обсудить этот вопрос мылом alexey@entesoft.com. Парсер для XML (кстати, HTML является подмножеством XML) есть под любую платформу.


(Reply to this) (Parent)


[info]dmierkin
2002-11-18 06:44 (link)
сам журнал без комментов можно сохранить проще:

http://www.livejournal.com/export.bml

(Reply to this) (Thread)


[info]tiphareth
2002-11-18 10:30 (link)

Я знаю. Но для чужого журнала сие не работает.

Привет
Миша.

(Reply to this) (Parent)


(Post a new comment)


[ Home | Update Journal | Login/Logout | Browse Options | Site Map ]