William wrote:
>> 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.

My apologies, I'm afraid we lost track of your purpose. My best advice is to
force the value to numeric or string at the point of call and *comment* it so
that it doesn't look like a mistake.

  my $ypm = '17'.'60';
  dbase_function($ypm+0);          # Call requires a numeric value

or

  my $index = sprintf '%05d', $n;
  dbase_function("$index");        # Call requires a string value

HTH,

Rob


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


Reply via email to