Почему?

Dec 19, 2008 11:30


Что-то не могу понять, почему sprintf @_ возвращает не строку, а число элементов в списке, словно это и не sprintf, а какой-нибудь scalar. Странно!
куча кода )

недоумение, программизм, perl

Leave a comment

Comments 3

ping8 December 19 2008, 06:36:58 UTC
Покажи мне, где в sprintf @_ описание формата, а где аргументы.

Reply

ping8 December 19 2008, 06:43:24 UTC
perldoc -f sprintf

Unlike "printf", "sprintf" does not do what you probably mean
when you pass it an array as your first argument. The array is
given scalar context, and instead of using the 0th element of
the array as the format, Perl will use the count of elements in

Reply

Где shoorick December 19 2008, 08:43:56 UTC
Ну я-то наивно предполагал, что sprintf возьмёт $_[0] как описание формата, а всё остальное - как аргументы. Оказалось, нифига: товарищ анонимус в ru_perl зацитировал perldoc -f sprintf:Unlike "printf", "sprintf" does not do what you probably mean when you pass it an array as your first argument. The array is given scalar context, and instead of using the 0th element of the array as the format, Perl will use the count of elements in the array as the format, which is almost never useful.
Типа, так и задумано.

Reply


Leave a comment

Up