C. Chad Wallace wrote:
> At 10:39 AM on 15 May 2008, Robert Hicks wrote:
>
>> C. Chad Wallace wrote:
>>> At 7:05 PM on 14 May 2008, Robert Hicks wrote:
>>>
>>>> Because I am building 2 types of emails...I have 2
>>>> $template->process commands and because it is in a loop and I have
>>>> 5 users, I get five error message when a template is incorrect.
>>>>
>>>> What I would like to do is catch the errors and only pass the
>>>> unique ones to STDERR.
>>>>
>>>> I am not sure if that is enough to go on.
>>> How about: instead of calling die, you save the error info in a
>>> hash, and then at the end of the loop, "warn" the unique ones.
>>>
>>>
>> I am not sure how to do that. Would I:
>>
>> my %error_hash = ();
>>
>> [ HTML ]
>> $template->process( code ) || $error_hash{ 'key' } = $template->error;
>>
>> [ TEXT ]
>> $template->process( code ) || $error_hash{ 'key' } = $template->error;
>>
>> Then later find the unique keys in that hash?
>
> I was thinking something like this:
>
> $template->process( code ) || $error_hash{ $template->error }++;
>
> That way the hash takes care of duplicate error messages, and keeps a
> count of occurrences of each one.
>
> Then:
>
> while ( my ( $err, $count ) = keys %error_hash ) {
> warn "[$count] $err";
> }
>
> And instead of:
>
> Your head is on backwards at ...
> Your head is on backwards at ...
> Your head is on backwards at ...
> Your head is on backwards at ...
> Your head is on backwards at ...
>
> You'd get:
>
> [5] Your head is on backwards at ...
>
> If you want different counts for HTML and TEXT, you could have two
> error hashes.
>
> Oh... I wonder, does the $template->error string contain an 'at ...'
> portion? If so, and if each one gives a different line number, then
> you'd have to strip those off to get it down to the basic error
> message ... otherwise, the hash won't see them as duplicates.
>
>
Thank you very much.
Robert
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates