Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Convert perl script to global

Quote Reply
Convert perl script to global
I have a perl script:
Code:
use strict ;
use Date::Manip ;
$main::TZ='GMT' ; ##set this to your time zone
&Date_Init("DateFormat=US"); ##enforce mm/dd format for all dates.
sub calc_wrk ($$) {
print &UnixDate(Date_NextWorkDay(@_),do{$_[1]>0? "$_[1] working days from today would be":"Today is"}. " %A, the %E of %B, %Y\n") ;
}
my ($d,$m,$y)=(localtime)[3,4,5] ;
my $date=join '/',($m+1,$d,$y+1900) ;
calc_wrk($date,0) ;
calc_wrk($date,10) ;
calc_wrk($date,15) ;
I set up a global called 'workdays' and cut and paste this code surrounded by sub {}. However, when I did a static build with the page containing the global the output acutally appeared in the build script not on the page as inteneded. What do I need to change to make the output show on my html page?

Many Thanks.
Alex



Indigo Clothing is a t-shirt printing company based in the UK.
Indigo Clothing | Promotional Clothing | T-Shirt Printing | Embroidery
Quote Reply
Re: [IndigoClothing] Convert perl script to global In reply to
Hi Alex,

Something like below should work.

Code:
use strict ;
use Date::Manip ;
$main::TZ='GMT' ; ##set this to your time zone
&Date_Init("DateFormat=US"); ##enforce mm/dd format for all dates.
sub calc_wrk ($$) {
return &UnixDate(Date_NextWorkDay(@_),do{$_[1]>0? "$_[1] working days from today would be":"Today is"}. " %A, the %E of %B, %Y\n") ;
}
my ($d,$m,$y)=(localtime)[3,4,5] ;
my $date=join '/',($m+1,$d,$y+1900) ;
my $output="";

$output .="<br>" . calc_wrk($date,0) ;
$output .="<br>" .calc_wrk($date,10) ;
$output .="<br>" .calc_wrk($date,15) ;return $output;

Cheers,

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] Convert perl script to global In reply to
Dat,

Thanks for the quick response but same issue as the output:
Code:
Today is Monday, the 20th of February, 2006
10 working days from today would be Monday, the 6th of March, 2006
15 working days from today would be Monday, the 13th of March, 2006
Appears in the build script output rather than on the html page which oddly has the figure one where the global should be.

Alex



Indigo Clothing is a t-shirt printing company based in the UK.
Indigo Clothing | Promotional Clothing | T-Shirt Printing | Embroidery
Quote Reply
Re: [IndigoClothing] Convert perl script to global In reply to
That's strange. How do use the global in the template?

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] Convert perl script to global In reply to
Code:
<html>

<head>
<title><%title_unlinked%></title>
</head>

<body>

<h1><%page_title%></h1>

<p><%title_linked%></p>

<%workdays%>

</body>
</html>



Indigo Clothing is a t-shirt printing company based in the UK.
Indigo Clothing | Promotional Clothing | T-Shirt Printing | Embroidery
Quote Reply
Re: [IndigoClothing] Convert perl script to global In reply to
Hi Alex,

I have tested with LinksSQL2.x. It's working fine.

Please ensure that you have changed the 'print' command to the 'return' one in that global.

Hope that helps!

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] Convert perl script to global In reply to
Redid the global, now working. Thank you!



Indigo Clothing is a t-shirt printing company based in the UK.
Indigo Clothing | Promotional Clothing | T-Shirt Printing | Embroidery
Quote Reply
Re: [IndigoClothing] Convert perl script to global In reply to
My pleasure!

Cheers,

Cheers,

Dat

Programming and creating plugins and templates
Blog