Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Perl4Win32: prettify code syntax

by Intrepid (Deacon)
on Jul 20, 2000 at 11:01 UTC ( #23332=snippet: print w/ replies, xml ) Need Help??

Description:

Use code2html
to syntax-highlight and HTML-ify your code before posting to
'Monks, etc. This is a perl one-liner to work with code2html
utilizing Win32::Clipboard to transmogrify the code without writing
files which then would have to be opened, copied, etc.

perl -"MWin32::Clipboard" -e "$tmp=$ENV{'TEMP'};
$tmp.='\tmpcode2html'; $tmp=~s#\\#\\\\#g;
$clp=Win32::Clipboard(); $it=$clp->Get(); open(CH,\"^|perl -S
code2html -v -lperl -ohtml-dark ^>$tmp\") or die $!;
print CH $it; close CH; $tmp=~s#\\\\#/#g; open(TF,$tmp);
read(TF,$it,(-s $tmp));$clp->Set($it); unlink $tmp;"

Please note that this looks all wrong to UNI* gurus who see the quoting through typical shell rules that apply there; Win is different and there's a couple of not-well-known Windoze shell escaping tricks demonstrated in this code, as well.

Also shows how to open a pipe to a process to be written to by Perl, has the ugly kludge of writing a tmp file -- if anyone knows a *Windoze*-workable way to avoid this please comment.

Comment on Perl4Win32: prettify code syntax

Back to Snippets Section

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (17)
As of 2015-07-07 19:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls