Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

fake SSI

by akm2 (Scribe)
on May 01, 2001 at 22:14 UTC ( [id://77053]=perlquestion: print w/replies, xml ) Need Help??

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

a=shift;$a=~s/\\//g;$a=glob($a);$_=`cat $a`;print"Content-type: text/h +tml\n\n" ;while(/<!--#exec cgi="([^"]*)"-->/){$a=`$1`;$a=~s/\n/<br>\n/g; s/<!--#exec cgi="([^"]*)"-->/$a/}print;

is code I found on the net to handle SSI's. Im a little confused. This code is being applied on $a, right? That needs to change to my var name, yes? Or is all of this being applied to $_? if it is being applied to $HTMLLine?

Replies are listed 'Best First'.
(tye)Re: fake SSI
by tye (Sage) on May 01, 2001 at 23:23 UTC
    a=shift;$a=~s/\\//g;$a=glob($a);$_=`cat $a`;print"Content-type: text/h +tml\n\n" ;while(/<!--#exec cgi="([^"]*)"-->/){$a=`$1`;$a=~s/\n/<br>\n/g; s/<!--#exec cgi="([^"]*)"-->/$a/}print;

    Let's break that down. It appears that the first part is really meant to be:

    my $a= shift @ARGV; $a =~ s#\\#/#g; $a= glob($a); $_= `cat $a`;
    which is just Win32-specific bad Perl for: $_= do { local($/); <> }; that is, take a file specified on the command line and read its contents into $_.

    Now the next bit translates to:

    print "Content-type: text/html\n\n"; while( /<!--#exec cgi="([^"]*)"-->/ ) { my $a= `$1`; $a =~ s/\n/<br>\n/g; s/<!--#exec cgi="([^"]*)"-->/$a/ } print;
    which isn't so bad. A big unflexible, sure. If you aren't used to Perl's implicit $_, here is an alternate version:
    while( $_ =~ /<!--#exec cgi="([^"]*)"-->/ ) { my $a= `$1`; $a =~ s/\n/<br>\n/g; $_ =~ s/<!--#exec cgi="([^"]*)"-->/$a/; } print $_;

    Does that help?

            - tye (but my friends call me "Tye")
Re: fake SSI
by dvergin (Monsignor) on May 01, 2001 at 23:56 UTC
    First off, the words, "code I found on the net" send shivers up the spine. My advice: look at the CPAN modules found here.

    Having said that, let's take a look at a visually enhanced version of what you found.

    sub print_html_page_w_ssi { # grab the .html filename passed as a parameter $a = shift; # zap any backslashes in the name # (note: we seem to be on a windows machine) $a =~ s/\\//g; # spiff up the filename, if needed $a = glob($a); # grab its contents (i.e. the html code itself) in $_ $_ = `cat $a`; # print out the http header print "Content-type: text/html\n\n"; # process any ssi tags in $_ one-by-one while ( /<!--#exec cgi="([^"]*)"-->/ ) { # now the name of the ssi file is in $1 # run that file and grab its output in $a $a = `$1`; # put a <br> with each line terminator $a =~ s/\n/<br>\n/g; # and substitute that output for # the ssi tag where it occurs in $_ s/<!--#exec cgi="([^"]*)"-->/$a/; } # print the resulting page (which is still # in $_) to the waiting web client print; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://77053]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-03-29 07:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found