in reply to Re: Scripts work under perl .exe but not ISAPI
in thread Scripts work under perl .exe but not ISAPI

Taking your idea to print out $NewsPost to see what was in it I have found that everything is going right UNTILL I call the sub &ProcessHTML(); It seams the array I use to hold the news is not auto-passed to the sub like in perl for CGI (.exe)
  • Comment on Re^2: Scripts work under perl .exe but not ISAPI

Replies are listed 'Best First'.
Re^3: Scripts work under perl .exe but not ISAPI (~= mod_perl?)
by tye (Sage) on Oct 24, 2009 at 12:03 UTC

    This sounds very much like the "will not stay shared" warning that you can get when you take a CGI and use it in mod_perl. Does ISAPI.dll wrap the *.pl file into a subroutine like Apache::Registry does?

    The descriptions of Perl for ISAPI make it sound much like mod_perl / Apache::Registry but I could not find any cases of anybody actually documenting what it does or even mentioning "wrapping the script in a sub" much less noting the need to deal with file-scoped lexicals being used by subs in order to avoid "will not stay shared" problems (but I didn't spend a lot of time searching and scanning).

    The linked searches should find you a lot of information about this problem in case you are interested in understanding it better.

    If this is indeed the same problem, then the least-change way to fix your script would be to go from its current pattern:

    declare and initialize variables with static data code to be run subroutines that use above variables

    to a pattern like:

    BEGIN { declare and initialize variables with static data Main(); sub Main { code to be run } subroutines that use above variables }

    So you can probably fix your script by adding 5 lines of code ("BEGIN {", "Main();", "sub Main {", "}", and "}").

    But such a change will leave your script easy to break under mod_perl / PerlIS because it will be easy to stick something that isn't "declare and initialize variables with static data" into that first chunk of code. Which is why you might want to learn more about this particular problem and why you have to do these things to avoid it.

    This is just one of the reason why I still code in a style very much like the one I outlined long ago at (tye)Re: Stupid question (now updated with some justifications).

    - tye        

Re^3: Scripts work under perl .exe but not ISAPI
by Anonymous Monk on Oct 24, 2009 at 07:10 UTC
    It seams the array I use to hold the news is not auto-passed to the sub like in perl for CGI (.exe)

    It is never auto-passed, it is merely in scope. You should read Coping with Scoping

Re^3: Scripts work under perl .exe but not ISAPI
by Anonymous Monk on Oct 24, 2009 at 07:47 UTC
    Here is how you might rewrite that code
    #!/usr/bin/perl -- use strict; use warnings; { use CGI qw~ -nph :standard ~; my $BasePath = 'D:/finalfantasyinfo/community'; print header, start_html; MyNewsBoardApp::PrintSomeNews("$BasePath/boards/news.txt"); print end_html; exit; } package MyNewsBoardApp; use strict; use warnings; use POSIX; sub PrintSomeNews { my $NewsBoardFile = shift; my @NewsBoard = GetNewsBoard($NewsBoardFile); my $i = 0; while ( $i < 4 ) { print PostToHtml( GetNewsPost( $NewsBoard[$i][0] ) ); $i++; } } sub GetNewsBoard { use autodie qw' open close '; open my $NewsFh, shift; my @News = map { [ split /\|/, $_ ] } sort { $b <=> $a } <$NewsFh>; close $NewsFh; return @News; } sub GetNewsPost { use autodie qw' open close '; open my $NewsFh, shift; my $News = join '', $NewsFh; close $NewsFh; return split /\|/, $News; } sub PostToHtml { my (@News) = @_; my $ID = $News[3]; my $Time = POSIX::strftime( q!%H:%m %p on %B, %Y!, localtime( $New +s[3] ); $News[8] =~ s/\[(\/)?(b|u|i)\]/<$1$2>/gi; $News[8] =~ s~\[center](.*?)\[/center]~<center>$1</center>~gi; $News[8] =~ s~\[url=(\S+?)\](.*?)\[/url\]~<a href="$1">$2</a>~gi; $News[8] =~ s~\[img](.*?)\[/img\]~<img src="$1" alt="" />~gi; $News[8] =~ s~\s*\[\*\]~</li><li>~isg; $News[8] =~ s~\[olist\]~<ol>~isg; $News[8] =~ s~\s*\[/olist\]~</li></ol>~isg; $News[8] =~ s~</li><ol>~<ol>~isg; $News[8] =~ s~<ol></li>~<ol>~isg; $News[8] =~ s~\[list\]~<ul>~isg; $News[8] =~ s~\s*\[/list\]~</li></ul>~isg; $News[8] =~ s~</li><ul>~<ul>~isg; $News[8] =~ s~<ul></li>~<ul>~isg; $News[8] =~ s~\[ch9679\]~&#9679\;~isg; return qq~<p class="center"><span class="header">$News[0]</span> <br />Posted by: $News[1] at $Time</p> <p>$News[8]</p> <p style="text-align: right"><a href="http://www.ffinfo.com/community/YaBB.pl?num=$ID">Discuss this po +sting. </a></p>~; } __END__
    For debugging you should use print escapeHTML( Dumper( $var, \@var, \%var ) );

    See autodie, POSIX