in reply to Parsing Code

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!

Replies are listed 'Best First'.
Re: Re: Parsing Code
by Anonymous Monk on Sep 17, 2002 at 19:34 UTC
    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!
        HI again! Yes the sub weather is in the same file. here is the code again with your suggestion.

        sub index { #&top_nav; #&weather; #$weatherData = &main; $weatherData = &weather; # $weatherData = weather(); &date; #read in template page for INDEX.HTML################################# +###### my $templateFileIndex="../htdocs/temp_test/index.html"; open(INFILE,"<$templateFileIndex"); my @templatePageIndex=<INFILE>; close(INFILE); #condense page array into one scalar variable my $tIndex=join("",@templatePageIndex); #search-and-replace variables $tIndex=~s/%%INSERT DATE HERE%%/$liveDate/g; #my $weatherData= &weather; $tIndex=~s/%%WEATHER2%%/$test/g; #tIndex=~s/%%INSERT NAV HERE%%/$navPage/g; $tIndex=~s/%%WEATHER%%/$weatherData/g; #done, output page to browser #Now when this code reads the html file to do the replacements of the +variables the $weatherData prints the code from weather.cgi not the r +esult of it, that's the problem. print $tIndex; exit } ###################################################################### +###### sub weather { # read in footer template $foot="cgi-bin/weather/weather.cgi"; open(MYFOOT,"<$foot"); @footerPage=<MYFOOT>; close(MYFOOT); #condense page array into one scalar variable $weather=join("",@footerPage); $test="test"; return $weather; }

      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?

        Yes I did, and it's not a server right issue. All that I am trying to do is call the weather.cgi from another perl program that calls a html template so I can print to the browser the results from this scripts.