> use strict;
> use warnings;
> 
> use Devel::Peek qw/Dump/;
> 
> my $numstr = sprintf("%4d", 1234);
> Dump $numstr;
> 
> $numstr = sprintf("%05d", 1234);
> Dump $numstr;
> 
> my $num = sprintf("%05d", 1234);
> $num += 0;
> Dump $num;
> 
> **OUTPUT**
> 
> SV = PV(0x365ec) at 0x3652c
>   REFCNT = 1
>   FLAGS = (PADBUSY,PADMY,POK,pPOK)
>   PV = 0x182ea94 "1234"\0
>   CUR = 4
>   LEN = 8
> SV = PV(0x365ec) at 0x3652c
>   REFCNT = 1
>   FLAGS = (PADBUSY,PADMY,POK,pPOK)
>   PV = 0x182ea94 "01234"\0
>   CUR = 5
>   LEN = 8
> SV = PVIV(0x37604) at 0x357c4
>   REFCNT = 1
>   FLAGS = (PADBUSY,PADMY,IOK,pIOK)
>   IV = 1234
>   PV = 0x183ba74 "01234"\0
>   CUR = 5
>   LEN = 8
> 
> So in the first two cases you can see that the POK flag (denoting a string
> value) is set, but in the third case, after adding zero, the IOK flag becomes
> set (indicating an integer) while the POK flag is cleared, meaning that the 
> the
> string value is no longer valid, even though there is still space allocated 
> for
> it and its value is unchanged.

Thank you, now it's very clear to me. So scalar variable might look very 
flexible to our programmer's eyes as it can contain either integer or string, 
but I never know what is happening behind the scene until you show me that one. 
It create a big problem to me when I did not convert it to integer first before 
getting into the SWI-Prolog . Because Perl string means atom in SWI-Prolog, 
only Perl number means number in SWI-Prolog.

Thanks,

William


Send instant messages to your online friends http://uk.messenger.yahoo.com

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to