nataraj: (Default)
[personal profile] nataraj
Scalar::Util
       dualvar NUM, STRING
           Returns a scalar that has the value NUM in a numeric context and the value STRING in a string context.

               $foo = dualvar 10, "Hello";
               $num = $foo + 2;                    # 12
               $str = $foo . " world";             # Hello world


Господи! Это каких же глюков можно наловить!

PS: Там еще в конце забавно: The weaken and isweak subroutines in this module and the patch to the core Perl were written in connection with the APress book ‘Tuomas J. Lukka’s Definitive Guide to Object-Oriented Programming in Perl’, to avoid explaining why certain things would have to be done in cumbersome ways.

Date: 2011-01-05 07:20 pm (UTC)
From: [identity profile] beldmit.livejournal.com
О! Книжку надо заказать...

Date: 2011-01-05 07:27 pm (UTC)
From: [identity profile] what-me.livejournal.com
С глюками понятно, а вот какую пользу можно получить от применения dualvar?
Chromatic предлагает использовать для дебага
my $width = dualvar 800, 'Screen width';
my $height = dualvar 600, 'Screen height';
printf STDERR '%s is %d', $var, $var;

Но меня что-то не прёт.

Date: 2011-01-05 07:57 pm (UTC)
ext_613079: Default userpic (Default)
From: [identity profile] shaplov.livejournal.com
Ну примерно да... одновременно и код ошибки и описание как вариант... Но только это подкладывает мега-грабли любому кто этот код будет читать... нельзя так с людьми...

Date: 2011-01-05 08:09 pm (UTC)
From: [identity profile] maravan.livejournal.com
О, ты тоже нашел эту замечательную функциональность?

Date: 2011-01-05 08:44 pm (UTC)
From: [identity profile] qkowlew.livejournal.com
Терпеть не могу «заимствованные из бейсика неявные указания типов», а в данном случае ещё и неявное указание элемента структуры.
Ржал.

Date: 2011-01-09 07:09 am (UTC)
ext_613079: Default userpic (Default)
From: [identity profile] shaplov.livejournal.com
В бейсике, как я его помню, все-таки с типами было более или менее определенно. Есть доллар в конце -- строка. Нету -- число. Видимо по любому действительное... Хотя как оно там реально в памяти хранилось -- не знаю...

Profile

nataraj: (Default)
Swami Dhyan Nataraj

July 2024

S M T W T F S
 123456
789 10111213
14151617181920
21222324252627
28293031   

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 4th, 2025 12:53 am
Powered by Dreamwidth Studios
OSZAR »