Using Perl to Generate Code for SHJS SetupSaturday, January 31st, 2009 with No Comments »

Using SHJS for syntax colouring requires includes for each language. Here’s a simple Perl script to generate these includes if you downloaded all the files to a directory and was too lazy to manually type them out

opendir(DIR, ".");
@jsFiles = grep(/\.js$/,readdir(DIR));

$output = '<script type="text/javascript" src="sh_main.js"></script>';
$output .= "\n";

foreach $file(@jsFiles)
{
  $output .= '<script type="text/javascript"';
  $output .= 'src="lang/'.$file.'"></script>'."\n";
}

$output .= '<link type="text/css" rel="stylesheet"';
$output .= 'href="css/sh_style.css">'."\n";

open(FILE, ">generate.txt") or die("Error");
print FILE $output;
Get updates as often as we post! Subscribe to our full feed or comments feed.