Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Interchange: users

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

 

 

Interchange users RSS feed   Index | Next | Previous | View Threaded


lists at gmnet

Sep 6, 2011, 12:43 PM

Post #1 of 2 (122 views)
Permalink
{Spam?} Re: Leading 0 - calc issue.

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?

Rick






_______________________________________________
interchange-users mailing list
interchange-users [at] icdevgroup
http://www.icdevgroup.org/mailman/listinfo/interchange-users


peter at pajamian

Sep 6, 2011, 1:02 PM

Post #2 of 2 (117 views)
Permalink
Re: {Spam?} Re: Leading 0 - calc issue. [In reply to]

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

_______________________________________________
interchange-users mailing list
interchange-users [at] icdevgroup
http://www.icdevgroup.org/mailman/listinfo/interchange-users

Interchange users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.