PerlCode Breaking; Reason not Apparent

Discuss news styles, css code, and other Coranto customizations in here...the possibilities are endless, so have at it!

Moderator: Spunkmeyer

PerlCode Breaking; Reason not Apparent

Postby Gansos » Tue May 25, 2004 4:22 am

I am designing a style that essentially circumvents Coranto's method of archiving. I am creating a site for a theater house, and they want a calendar of upcoming shows. Each post has a field called "CustomField_enddate" that is a user-specified end date for the show (in the format YYYY-MM-DD). Using this style, Coranto should parse that field, and compare it against the current date. If the end date of the show is in the future, the news item is printed. If the end date is the current date, a different style is printed. If the end date has passed, the news item is omitted.

I have written some code that should accomplish all of this, and when checked with perl -cw on the command line, it validates syntactically. However, when I add this code to the style, Coranto gives the following error:

Error: That style is invalid and has a syntax error. Check, in particular, that all ifs are properly matched and ended. Perl reported the following error, which may or may not be helpful: Unmatched right curly bracket at (eval 11) line 60, at end of line syntax error at (eval 11) line 60, near "; }"

And the exact style with code is:
Code: Select all
<PerlCode>
##Find the number of days since day 0 to the end date of the show##

#parse enddate field
@date = split(/-/, $CustomField_enddate);

#map month numbers to number of days per month
%months = ( 1=> "31",
         2=> "29",
         3=> "31",
         4=> "30",
         5=> "31",
         6=> "30",
         7=> "31",
         8=> "31",
         9=> "30",
         10=> "31",
         11=> "30",
         12=> "31" );
         
#exclude the current month so it can be prorated
$lastmonth = $date[1]-1;

#correct for zero value months
if ($lastmonth == 0) { $lastmonth = 12; }

#tally the number of days elapsed since the beginning of this year
$monthd = 0;
foreach $month (keys %months) {
   if ($month <= $lastmonth) {
      $monthd = $monthd + $months{$month};
      }
}

#get number of days in all years past (exclude this one)
$yeard = (($date[0] - 1) * 365);
#number of days since day 0
$tdays = ($yeard + $monthd + $date[2]);

##Get the number of days since day 0 to today
($sec,$min,$hr,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

   $year = $year + 1900 - 1;
   $yeardnow = $year * 365;
   
   $tdaysnow = $year + $yeardnow;
   
#generate printcodes for Coranto style   
if ( $tdays > $tdaysnow ) { $printcode = 1; }
elsif ( $tdays = $tdaysnow ) { $printcode = 2; }
else { $printcode = 0; }
</PerlCode>

<If: Field: printcode == 1><Field: Subject></If><If: Field: printcode == 2>Closing Night for <Field: Subject></If>


What's going on here? Thanks for any and all help![/i]
Gansos
 
Posts: 62
Joined: Thu Jan 11, 2007 8:33 pm

Postby bozoka45 » Tue May 25, 2004 5:01 am

Hm. I have version 1.02 and just tried putting that into a style and it gave me the OK. What version do you have? Perhaps something with the version would make a difference?
User avatar
bozoka45
 
Posts: 1159
Joined: Sun Mar 23, 2003 8:38 pm
Location: New Orleans

Re: PerlCode Breaking; Reason not Apparent

Postby Parahead » Tue May 25, 2004 7:05 am

gansos wrote:What's going on here? Thanks for any and all help!
If you are using version 1.23 I think this thread would be interesting to you...
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden

Postby Gansos » Tue May 25, 2004 7:39 am

I'm using 1.23, the latest release.

It looks like the perl is valid, but the style code is causing problems. When I paste the perl into the style without the <If> tags, it works fine. When I use the following after the perl, it breaks:
Code: Select all
<If: Field: printcode == 1>do something</If>


Also, depending on exactly what I use, I get different errors. The previous gives me a different error than:
Code: Select all
<If: Field: printcode == 1>do something<If: Else>do something else</If>


This looks like a problem with Coranto. Maybe I'm breaking some rule I don't know about?
Gansos
 
Posts: 62
Joined: Thu Jan 11, 2007 8:33 pm

Postby Gansos » Tue May 25, 2004 7:49 am

Thanks Parahead! That solved it. Is there a new version of Coranto out with that bugfix?

Thanks!!

[p.s. the perl code in my original post is actually not correct (syntax is ok, but the result is a little off). I won't bother posting the revised code as it is not directly related to the point of my question. If anyone requests it however, I would be more than happy to post the final version.]
Gansos
 
Posts: 62
Joined: Thu Jan 11, 2007 8:33 pm

Postby Parahead » Tue May 25, 2004 1:43 pm

gansos wrote:Thanks Parahead! That solved it. Is there a new version of Coranto out with that bugfix?
Nop, I have made a post about this in the Coranto 1.23 thread, but hasn´t heard anything from cerberos76 or Lawrence about fixing this yet...
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden

Postby bozoka45 » Wed May 26, 2004 12:23 am

gansos wrote:Thanks Parahead! That solved it. Is there a new version of Coranto out with that bugfix?

Thanks!!

[p.s. the perl code in my original post is actually not correct (syntax is ok, but the result is a little off). I won't bother posting the revised code as it is not directly related to the point of my question. If anyone requests it however, I would be more than happy to post the final version.]


Please do, I'm sure one of the mods would be able to add it to the "Q&A" section.
User avatar
bozoka45
 
Posts: 1159
Joined: Sun Mar 23, 2003 8:38 pm
Location: New Orleans

Re: PerlCode Breaking; Reason not Apparent

Postby Parahead » Wed May 26, 2004 6:44 am

gansos wrote:I am designing a style that essentially circumvents Coranto's method of archiving. I am creating a site for a theater house, and they want a calendar of upcoming shows. Each post has a field called "CustomField_enddate" that is a user-specified end date for the show (in the format YYYY-MM-DD). Using this style, Coranto should parse that field, and compare it against the current date. If the end date of the show is in the future, the news item is printed. If the end date is the current date, a different style is printed. If the end date has passed, the news item is omitted.
I was so into reading about the If/Else-problem last time I read this post and I don´t want to disturb your circles or anything, but you do know that latest version of ChangeDateNew has the possibility to change the publishingdate and specify an enddate of a newsitem? It can both publish future posts and filter out old posts... This requires a daily build for you though, but it looks like you need that with your solution as well?

In a future version it might also be possible to change the category of a newsitem when the enddate has passed, for example making it possible to publish it in an archive rather than just filtering it out...
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden


Return to Customization

Who is online

Users browsing this forum: No registered users and 0 guests