Syntax::Highlight::Perl


A

alexjaquet

Hi,

I'm trying to use Syntax::Highlight::perl but the problem I get is when
I print the result I didn't get carriage return between lines.

thx

Here my script :

#!c:/Perl/bin/perl.exe
#usage
http://avant-garde.no-ip.biz/cgi-bin/edit.cgi?action=edit&filename=edit.cgi&dir=C:\Apache2\cgi-bin/
use strict;
use CGI;
use Syntax::Highlight::perl;

local our $query = CGI->new ;
local our $action = $query->param("action");
local our $dir = $query->param("dir");
local our $filename = $query->param("filename");
local our %VALUE;
local our $current_dir = "C:/Apache2/htdocs/edit";
local our $filedir = "C:/Apache2/cgi-bin/";

if ($action eq "edit") {edit(); }
elsif ($action eq "save") {save(); }


sub edit {
local our $content;
local our $content2;
open (FILE, "<$dir/$filename") or die "cannot open file
$dir/$filename";
while (<FILE>) {
$content .= $_;
}
close (FILE);

open (FILE, "<$current_dir/edit.html") or die "cannot open file
$current_dir/edit.html";
while (<FILE>) {
s/\$VALUE{'filename'}/$filename/g;
s/\$VALUE{'dir'}/$dir/g;
s/\$VALUE/$content/g;
$content2 .= $_;

}
print "Content-Type: text/html\n\n";
$content2 = colorize($filename,$dir);
print $content2;
}

sub save {
local our
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime();
local our $date = sprintf "%4d-%02d-%02d",$year+1900,$mon+1,$mday;
local our $time = sprintf("%4d:%02d:%02d",$hour,$min,$sec);

local our $old_file = $filename .".$date $time";
rename $filedir ."/" . $filename, $filedir ."/" . $old_file;
print "Content-Type: text/html\n\n";
print "Saved";
}

sub colorize {
my $file = shift || '';
my $dir = shift || '';
my $color_table = {
'Variable_Scalar' => 'color:#080;',
'Variable_Array' => 'color:#f70;',
'Variable_Hash' => 'color:#80f;',
'Variable_Typeglob' => 'color:#f03;',
'Subroutine' => 'color:#980;',
'Quote' => 'color:#00a;',
'String' => 'color:#00a;',
'Comment_Normal' => 'color:#069;font-style:italic;',
'Comment_POD' => 'color:#014;font-family:' .
'garamond,serif;font-size:11pt;',
'Bareword' => 'color:#3A3;',
'Package' => 'color:#900;',
'Number' => 'color:#f0f;',
'Operator' => 'color:#000;',
'Symbol' => 'color:#000;',
'Keyword' => 'color:#000;',
'Builtin_Operator' => 'color:#300;',
'Builtin_Function' => 'color:#001;',
'Character' => 'color:#800;',
'Directive' => 'color:#399;font-style:italic;',
'Label' => 'color:#939;font-style:italic;',
'Line' => 'color:#000;',
};

# Program proper
#=====================================================================

my $formatter = Syntax::Highlight::perl->new();

$formatter->define_substitution('<' => '&lt;',
'>' => '&gt;',
'&' => '&amp;'); # HTML escapes.

# install the formats set up above
while ( my ( $type, $style ) = each %{$color_table} ) {

$formatter->set_format($type, [ qq|<span style="$style">|,
'</span>' ] );
}



open F, '<', $dir."/".$file or die $!;

$formatter .'<pre style="font-size:10pt;color:#336;">';
while (<F>) {
print $formatter->format_string;
$formatter ."<br/>";
}
$formatter ."</pre>";
return $formatter->format_string;
}
 
Ad

Advertisements

A

alexjaquet

solved by changing to :

open F, '<', $dir."/".$file or die $!;

$formatter .'<pre style="font-size:10pt;color:#336;">';
my $content;
while (<F>) {
$content .='<br/>';
$content .= $formatter->format_string
}
$content .="</pre>";
}
 
Ad

Advertisements

T

Tad McClellan

local our $query = CGI->new ;
local our $action = $query->param("action");
local our $dir = $query->param("dir");
local our $filename = $query->param("filename");
local our %VALUE;
local our $current_dir = "C:/Apache2/htdocs/edit";
local our $filedir = "C:/Apache2/cgi-bin/";
local our $content;
local our $content2;
local our
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime();
local our $date = sprintf "%4d-%02d-%02d",$year+1900,$mon+1,$mday;
local our $time = sprintf("%4d:%02d:%02d",$hour,$min,$sec);

local our $old_file = $filename .".$date $time";



Aaaaaaayyyy!



Date: Sat, 5 Nov 2005 13:45:35 -0600
TM> You should always prefer lexical variables over package variables,
TM> except when you can't.

TM> Why do you think that you cannot use lexical variables there?


Date: Sun, 15 Jan 2006 07:55:06 -0600
TM> I've asked you this before, but I don't think you responded, so in
TM> an effort to repair your obvious misunderstanding, I'll try asking
TM> once again:

TM> You should always prefer lexical variables over package variables,
TM> except when you can't.

TM> Why do you think that you cannot use lexical variables there?


Date: Mon, 13 Mar 2006 10:14:27 -0600
TM> I have asked you this twice before, but you never responded.

TM> It appears that you are misunderstanding something, you should
TM> consider getting a proper understanding.


TM> So, I'll try to help you a third (and last) time:

TM> You should always prefer lexical variables over package variables,
TM> except when you can't.

TM> Why do you think that you cannot use lexical variables there?

TM> If you do not understand the question, then ask a question about
TM> the question.

TM> You have an opportunity here to become a more knowledgeable
TM> Perl programmer.




This "talking to the hand" stuff is getting rather bothersome.

So long!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top