Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

SCS2CSS

by staeryatz (Monk)
on Nov 16, 2001 at 09:55 UTC ( [id://125769]=sourcecode: print w/replies, xml ) Need Help??
Category: HTML Utility
Author/Contact Info Jeffrey Bakker <jefskey at yahoo dot com>
Description: This is a utility for a larger program of mine, Webcpp (http://webcpp.sf.net). This utility will convert Webcpp's native colour schemes (*.scs) to CSS, which is a new compatible scheme format for the Webcpp 0.6+ series.
#!/usr/bin/perl -w

# this has been edited to fit chromatic's suggestions below

use strict;

my $scs = shift or die "Usage: $0 <scsfile>\n";
(my $css = $scs) =~ s/\.scs\z/.css/;

open(SCSFILE, "<$scs") or die "$!: cannot read $scs";
open(CSSFILE, ">$css") or die "$!: cannot write to $css";

my @scheme = <SCSFILE>;
chomp @scheme;
close(SCSFILE);

select(CSSFILE);

print<<"EOF";
/*** Webcpp 0.6.0+ compatible StyleSheet http://webcpp.sf.net ***/

body {background-color: $scheme[0]}

a:link    {color:$scheme[5]}
a:visited {color:$scheme[6]}
a:active  {color:$scheme[3]}
a:hover   {color:$scheme[1]}

pre {
color: $scheme[2];
font-size:100%
}

font {font-size:100%}

font.preproc {     /* preprocessor */
color: $scheme[1];
font-size:100%
}

font.nortext {     /* normal text */
color: $scheme[2];
font-size:100%
}

font.keyword {     /* keyword */
color: $scheme[3];
font-weight: bold;
font-size:100%
}

font.numbers {     /* number */
color: $scheme[4];
font-size:100%
}

font.strings {     /* string */
color: $scheme[5];
font-size:100%
}

font.comment {     /* comment */
color: $scheme[6];
font-style: italic;
font-size:100%
}

EOF

close(CSSFILE);
select(STDOUT);
print("woo-hooo!!\n");
Replies are listed 'Best First'.
Re: SCS2CSS
by chromatic (Archbishop) on Nov 20, 2001 at 09:31 UTC
    Care for a couple small suggestions?
    my $argc = @ARGV; if($argc != 1) { print "Usage: \$ $0 <scsfile>\n"; exit; } my $scs = $ARGV[0];
    This could be more succinct as:

    my $scs = shift or die "Usage: $0 <scsfile>\n";

    Don't forget to check the success of your open calls.

    You might want to escape the periods and anchor the ends of your regular expression. File::Basename might also come in handy, but may be severe overkill:

    (my $css = $scs) =~ s/\.scs\z/.css/;

    A heredoc would make the print statements somewhat more manageable. Roll on Perl 6 and intendable heredocs!

      Thanks for the tips. :)

      I never would have thought of putting the argument vector processing all in one line like that. I kinda just did it the 'C' way. Kudos to you.

      Ah, the heredoc operator...I don't know why I haven't thought of that one myself (I use it all the time for cgi). But the strangest thing of all, is why did I put my print staements in parenthesis?

      The mysteries of programming on \0 caffeine. This could be an X-File...

      Update: Okay, I finally changed it and tested it. It looks alot better now, thanks.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2024-04-19 19:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found