in reply to Re: Parsing Code
in thread Parsing Code

Yes I can do that but it prints literaly all the code from the weather.cgi. It doesn't execute the weather.cgi itself.

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

    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; }

        Mea culpa. I completely mis-read your problem.

        If you want to run code inside the file "cgi-bin/weather/weather.cgi", why are you opening it and reading its contents?

        The next question is what does the code inside that file look like? If it's a stand-alone program that uses (for example) LWP to obtain the weather info from another website, then to get that data into your calling script will depend on what that script does with the data? Write it to a file, print it to STDOUT etc.

        I think you will need to post the contents of that file before anyone will be able to advise you on how to get the data it generates into your program.


        Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!
Re: Re: Re: Parsing Code
by fglock (Vicar) on Sep 17, 2002 at 19:46 UTC

    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.