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 08:09 pm (UTC)
From: [identity profile] maravan.livejournal.com
О, ты тоже нашел эту замечательную функциональность?

Date: 2011-01-05 08:44 pm (UTC)
From: [identity profile] qkowlew.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 Jul. 7th, 2025 01:39 pm
Powered by Dreamwidth Studios