PERL and external stylesheets

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bluejay906
    New Member
    • Jun 2007
    • 19

    PERL and external stylesheets

    I have been trying to get a small script to generate an HTML page. I want one line of the page have a link to an external CSS file. I tried using:

    PRINT "<link.....>\n" ;

    to enter the line of code into the new file. I get no errors but I don't get the style either. I have done a Google search on this topic. There are several references I found that show using CGI.pm functions to do this. The SA of my site, though, says that using CGI.pm is unnecessary. Which is correct?
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    if you are using 'PRINT', that is wrong. All native perl functions are lowercase: 'print'.

    Printing a link to a style sheet using a fully qualified url:

    Code:
    print qq~<LINK REL="STYLESHEET" TYPE="text/css" HREF="http://www.yoursite.com/style/style.css" MEDIA="screen">\n~;
    Printing a link to a style sheet using a relative url:

    Code:
    print qq~<LINK REL="STYLESHEET" TYPE="text/css" HREF="../style/style.css" MEDIA="screen">\n~;
    You can use the CGI module too. If you are already using the CGI module you may as well stick with that.

    Comment

    • Bluejay906
      New Member
      • Jun 2007
      • 19

      #3
      Here is the code I am trying to get to work properly. I made the change you suggested:
      Code:
      #!/usr/bin/perl
      use DBI;
      #definition of variables
      $db="gcai";
      $host="localhost";
      $user="gcai";
      $password="ttaajj";
      #connect to MySQL database
      my $dbh   = DBI->connect ("DBI:mysql:database=$db:host=$host",
                                $user,
                                $password)
                                or die "Can't connect to database: $DBI::errstr\n";
      #prepare the query
      my $sth = $dbh->prepare( "
                    SELECT *
                    FROM employees");
      
      #execute the query
      $sth->execute( );
      
      print "Content-type: text/html\r\n\r\n";
      print "<HTML>\n";
      print "<HEAD><TITLE>Hello World!</TITLE>";
      #print "<LINK REL='StyleSheet' HREF='compass.css' TYPE='text/css'>\n";
      print qq~<LINK REL="STYLESHEET" TYPE="text/css" HREF="compass.css" MEDIA="screen">\n~;
      print "</HEAD>\n";
      print "<BODY>\n";
      print "<H2>Hello World!</H2>\n";
      print "<H2>Following is a Perl db example:</H2>\n";
      
      while ( my @row = $sth->fetchrow_array( ) )  {
               print "<BR>@row</BR>\n";
      }
      
      print "</BODY>\n";
      print "</HTML>\n";
      The page is not formatted by the stylesheet. What am I doing wrong?

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        the style sheet can not be in the cgi-bin, which I think is where you have it judging by the relative url:

        HREF="compass.c ss"

        put the style sheet in a different folder, one with regular http access, and use the relative url to that folder:

        HREF="../style/compass.css"


        where "style" is the name of the folder the compas.css file is in.

        Comment

        • Bluejay906
          New Member
          • Jun 2007
          • 19

          #5
          I had originally coded it to the CSS directory, but I moved it into the CGI-BIN when it didn't work. I did yhat you suggested and it worked. Thanks.

          Comment

          Working...