[ic] {Spam?} Re: Leading 0 - calc issue.

Peter peter at pajamian.dhs.org
Tue Sep 6 20:02:25 UTC 2011


On 07/09/11 07:43, Rick Bragg wrote:
> On Tue, 2011-09-06 at 15:27 -0400, Rick Bragg wrote:
>> I am trying to increment a number and keep it's leading 0.  (I need the
>> result to be 2 digits long)  
>>
>> The following works fine and returns "08":
>>
>> [tmp number]07[/tmp]
>> [calc]
>> my $num = [scratch number]+1;
>> $num = sprintf("%2d", $num);
>> $num =~ tr/ /0/;
>> return $num;
>> [/calc]
>>
>> However, if I use 08, or 09, I get "0" returned.  Any idea why?
>>
>> [tmp number]08[/tmp]
>> [calc]
>> my $num = [scratch number]+1;
>> $num = sprintf("%2d", $num);
>> $num =~ tr/ /0/;
>> return $num;
>> [/calc]
>>
>> [tmp number]09[/tmp]
>> [calc]
>> my $num = [scratch number]+1;
>> $num = sprintf("%2d", $num);
>> $num =~ tr/ /0/;
>> return $num;
>> [/calc]
>>
>> Thanks!
>> Rick
>>
> 
> 
> Using $Scratch->{number} fixes it but I'm just wondering why [scratch
> number] does not work?

Interchange interpolates the [scratch number] before the calc tag is run
so the perl just sees the bare number as if you'd typed it directly.
When you use $Scratch->{number} that is passed straight to the calc tag
and that is exactly what perl sees, so perl sees it as a variable which
it acts on differently to a bare number.


Peter



More information about the interchange-users mailing list