473,396 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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?
Jun 14 '07 #1
4 2520
KevinADC
4,059 Expert 2GB
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:

Expand|Select|Wrap|Line Numbers
  1. 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:

Expand|Select|Wrap|Line Numbers
  1. print qq~<LINK REL="STYLESHEET" TYPE="text/css" HREF="../style/style.css" MEDIA="screen">\n~;
  2.  
You can use the CGI module too. If you are already using the CGI module you may as well stick with that.
Jun 14 '07 #2
Here is the code I am trying to get to work properly. I made the change you suggested:
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use DBI;
  3. #definition of variables
  4. $db="gcai";
  5. $host="localhost";
  6. $user="gcai";
  7. $password="ttaajj";
  8. #connect to MySQL database
  9. my $dbh   = DBI->connect ("DBI:mysql:database=$db:host=$host",
  10.                           $user,
  11.                           $password)
  12.                           or die "Can't connect to database: $DBI::errstr\n";
  13. #prepare the query
  14. my $sth = $dbh->prepare( "
  15.               SELECT *
  16.               FROM employees");
  17.  
  18. #execute the query
  19. $sth->execute( );
  20.  
  21. print "Content-type: text/html\r\n\r\n";
  22. print "<HTML>\n";
  23. print "<HEAD><TITLE>Hello World!</TITLE>";
  24. #print "<LINK REL='StyleSheet' HREF='compass.css' TYPE='text/css'>\n";
  25. print qq~<LINK REL="STYLESHEET" TYPE="text/css" HREF="compass.css" MEDIA="screen">\n~;
  26. print "</HEAD>\n";
  27. print "<BODY>\n";
  28. print "<H2>Hello World!</H2>\n";
  29. print "<H2>Following is a Perl db example:</H2>\n";
  30.  
  31. while ( my @row = $sth->fetchrow_array( ) )  {
  32.          print "<BR>@row</BR>\n";
  33. }
  34.  
  35. print "</BODY>\n";
  36. print "</HTML>\n";
  37.  
The page is not formatted by the stylesheet. What am I doing wrong?
Jun 16 '07 #3
KevinADC
4,059 Expert 2GB
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.css"

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.
Jun 17 '07 #4
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.
Jun 28 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Christopher Benson-Manica | last post by:
Just FMI, if an external stylesheet is linked to a page (with <link>), will subsequent <style> tags override the values in the external stylesheet? -- Christopher Benson-Manica | I *should*...
26
by: HarryO | last post by:
I created an external stylesheet file 'styles.css' and an html file that includes the line: <LINK REL="stylesheet" TYPE="text/css" HREF="styles.css" Both the .css file and the html file reside...
12
by: relaxedrob | last post by:
Hi All! I have a page with with the following style information: <link rel="stylesheet" type="text/css" href="/eEmployment/eTech.css" /> <style type="text/css"> DIV.Application {...
11
by: Safalra | last post by:
I've always linked to external stylesheets using a line like: <link rel="stylesheet" href="style.css" type="text/css"> I recently installed the HTMLTidy extension for Firefox and it objected...
0
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile....
3
by: Nathan Gilbert | last post by:
I am wanting to use javascript to select between different *.css files dependent on the user's browser. I am also wanting to generate the html document containing this javascript dynamically using...
1
by: webotronics | last post by:
Hi, I need to add a timeout for external programs, as the external program sometimes never dies (it's a ClearQuest multisite call to the shipping server, that sometimes never ends, but simply...
3
by: tundal45 | last post by:
Hey Guys, I am trying to automate the process of loading data in our oracle server. As a part of that process, I am working on a perl script that loads external tables from data files. What I am...
4
by: vijayarl | last post by:
Hi All, i have the following software installed in my system : 1.OS: Win2k 2.Eclipse Version used :3.4.0 & even the perl too... 1. I have imported the my own perl project in Eclipse, when i...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.