Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

How to implement CSS in perl script.

by aalneyperl (Acolyte)
on Nov 30, 2007 at 12:20 UTC ( [id://654091]=perlquestion: print w/replies, xml ) Need Help??

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

Hi, This is one of my subroutine my script. Currently i am using print statement to display all the output in linux. I wish to use CSS to display the output in a browser. I specifically want to know what i need to code in perl script to get the output on the browser.
sub repl { print "********REPLICATION STATUS********\n\n"; my $rs = $dbh->prepare("show status like 'slave_running'"); my $rrdbs = $dbh->prepare("show variables like 'read_rnd_buffer_size'" +); $rs->execute(); $rrdbs->execute(); while(my @vall = $rs->fetchrow_array()) { print "Replication Slave Status: $vall[1]\n"; if($vall[1] eq 'ON') { print "The system is configured as Mysql Replication +SLAVE\n"; print " The following is the Slave Status\n"; my $mas_hos = $dbh->prepare("show slave status"); $mas_hos->execute(); while (my @val = $mas_hos->fetchrow_array()) { print "Slave_IO_State: $val[0]\n"; print "Master_host: $val[1]\n"; print "Slave_IO_Running: $val[10]\n" +; print "Slave_SQL_Running: $val[11]\n +\n"; #print "Seconds_Behind_master: $val[ +33]\n"; } $mas_hos->finish(); } } }
thanks.

Replies are listed 'Best First'.
Re: How to implement CSS in perl script.
by marto (Cardinal) on Nov 30, 2007 at 12:28 UTC
Re: How to implement CSS in perl script.
by tcf03 (Deacon) on Nov 30, 2007 at 13:32 UTC
    If you are using CGI:

    print start_html(-style=>{'src'=>'http://my.server.com/style.css'} );
    UPDATE From the looks of your code, you are not. So you could just do
    print qq|<link href="http://my.server.com/style.css" rel="stylesheet" +type="text/css"></link>|;
    Unless I am misunderstanding the question.
    Ted
    --
    "That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved."
      --Ralph Waldo Emerson
Re: How to implement CSS in perl script.
by Gangabass (Vicar) on Nov 30, 2007 at 14:08 UTC

    First you need to print (X)HTML (or XML) not plain text.

    Second you need to print correct HTTP header (to tell client browser what type of document you send).

    Third if you need CSS (do you mean stylesheet?) use stylesheet as your document type demand. So you may use <link ... /> tag or <style ...>...</style> for (X)HTML or maybe XSLT for XML...

      Hi Gangabass, I need to print the output in a simple HTML format..for example using cascading stylsheet i want to create a table with the variable names on the left coulum and there values on the right with some suggestion. Thanks.

        Maybe you need something like this:

        print "<table><thead><tr><th>Slave_IO_State</th><th>Master_host</th><t +h>Slave_IO_Running</th><th>Slave_SQL_Running</th></tr></thead><tbody> +"; while ( my @val = $mas_hos->fetchrow_array() ) { print "<tr><td>$val[0]</td>"; print "<td>$val[1]</td>"; print "<td>$val[10]</td>"; print "<td>$val[11]</td>"; #print "<td>$val[33]</td>"; print "</tr>\n" } print "</tbody></table>\n";
Re: How to implement CSS in perl script.
by sundialsvc4 (Abbot) on Nov 30, 2007 at 16:50 UTC

    As usual, there are several ways to do it. And if you are now being asked to produce the output of a script in a browser window you probably want to step back and look at the bigger requirement. You don't want to do one thing, then watch the scope “creep,” and thereby have to do that one-thing over and over again.

    If the request is “show me this in a browser,” then the request is probably, “put this into a web-site.” Does such a “web site” exist now, or are you being asked to build that, too?

    Let's go for the easy-assumption:   that miraculously an existing site does exist. In that case, you might be able to arrange for a CGI-handler to somehow invoke your script as a child, (back-tick?) capture the output, and insert it into an html <code> tag. Cheep-n-dirty but maybe it will work.

    The key point now is that “there are several ‘things that will work,’ and you need to know which one to pursue.” You need to formalize this program's true requirements before trying to select the way to build it.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-04-14 09:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found