Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a template thing going on but I need to include in the html template a cgi program for weather. In the program that calls for all the templates I have to call this weather.cgi and display on the html page, how can I do that? I know the way it's done now is wrong but someone could help me with that by looking at the code, I hope!. Thanks a lot!!!!

sub index { #&top_nav; &weather; &date; #read in template page for INDEX.HTML################################# +###### my $templateFileIndex="../../htdocs/temp_test/ia_index.html"; open(INFILE,"<$templateFileIndex"); my @templatePageIndex=<INFILE>; close(INFILE); #condense page array into one scalar variable my $tIndex=join("",@templatePageIndex); #search-and-replace on date, nav bar and variables $tIndex=~s/%%INSERT DATE HERE%%/$liveDate/g; #$tIndex=~s/%%BLURB%%/$blurb/g; #$tIndex=~s/%%AGENT_NAME%%/$agent_name/g; #$tIndex=~s/%%URL%%/$url/g; $tIndex=~s/%%WEATHER%%/$weather/g; $tIndex=~s/%%WEATHER2%%/$test/g; #tIndex=~s/%%INSERT NAV HERE%%/$navPage/g; #done, output page to browser print $tIndex; exit } ###################################################################### +###### sub weather { # read in footer template $foot='weather/weather.cgi'; open(MYFOOT,"<$foot"); @footerPage=<MYFOOT>; close(MYFOOT); #condense page array into one scalar variable $weather=join("",@footerPage); $test="Test Variable"; }

Replies are listed 'Best First'.
Re: Parsing Code
by BrowserUk (Patriarch) on Sep 17, 2002 at 19:15 UTC

    You need to return the data gathered in sub weather ie. change the last line to be:

    return $weather;

    You then need to capture that return value and assign it to something in the calling program ie.

    my $weatherData = &weather;

    Then you can do whatever you need to with the data.


    Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!
      Yes I can do that but it prints literaly all the code from the weather.cgi. It doesn't execute the weather.cgi itself.

        That'll teach me to not to cut&paste without thinking.

        Add () after the call

        my $weatherData = weather();

        I am assuming that sub weather{...} is in the same file as the calling sub? It's difficult to tell from your post.


        Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!

        prints literaly all the code

        Oops! Maybe it doesn't have 'execute' rights on the server. Check with your web admin ...

        By the way, did you use the #!/bin/perl line in the beginning?

Re: Parsing Code
by Aristotle (Chancellor) on Sep 17, 2002 at 21:43 UTC