Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Perl-Win32 "filter" shortcuts

by Intrepid (Deacon)
on Jul 03, 2000 at 10:41 UTC ( [id://20850]=CUFP: print w/replies, xml ) Need Help??

This special adaption or hybridization of the Perl one-liner and
the Windoze desktop environment allows users to set up a collection
of shortcuts that run operations in Perl. It is not drag-and-drop
in this instance, however. The text to be formatted (be it code or
simple comments) is first copied to the Windows clipboard, then
the shortcut is double-clicked. The processed text (which is now
HTML) is then pasted into the entry field in the browser window.

For users of Win32 Perl I want to share what I have cooked up to make posting remarks and code to PerlMonks a lot more automated, alluring ... Perl-ish. These could be termed "utility one-liners" but with a twist which makes them Win32-specific.

Snippet 1: format code

perl "-MHTML::FromText" "-MWin32::Clipboard" -e "$clp=Win32::Clipboard();$ct=$clp->Get(); $ct=text2html($ct,paras=>1,blockcode=>1,metachars=>1);$clp->Set($ct);"

Snippet 2: format ordinary comment or quoted text - step 1 -

perl "-MWin32::Clipboard" "-MText::Wrap=$columns,fill" -e "$clp=Win32::Clipboard();$ct=$clp->Get(); $columns=68;$ct=fill('','',$ct); $clp->Set($ct);"

Snippet 3: format ordinary comment text - step 2 -

perl "-MHTML::FromText" "-MWin32::Clipboard" -e "$clp=Win32::Clipboard();$ct=$clp->Get(); $ct=text2html($ct,paras=>1,blockquotes=>1,bold=>1,underline=>1,metachars=>1,urls=>1); $clp->Set($ct);"

Snippet 4: format quoted text - step 2 -

perl "-MHTML::FromText" "-MWin32::Clipboard" -e "$clp=Win32::Clipboard();$ct.=$clp->Get(); $ct=text2html($ct,lines=>1,spaces=>1,bold=>1,underline=>1,metachars=>1); $ct='<I><BLOCKQUOTE>'.$ct .'</I></BLOCKQUOTE>'; $clp->Set($ct);"

Snippet 5: deal with the square brackets - Perlmonks requires this extra step -

perl "-MWin32::Clipboard" -e "$clp=Win32::Clipboard();$s=$clp->Get();1 while( $s =~ s/ ([\[\]]) / sprintf \"&#%03u;\",ord $1 /exg);$clp->Set($s);"



To explain more clearly what I mean, I have created a little screenshot:
Each of these shortcuts has as its "Properties|Shortcut|Target" one of the perl one-liners shown here.
<IMG SRC="http://www.wonderstorm.com/cgi-bin/PNGem.pl?filtershortcuts" WIDTH=213 HEIGHT=153 HSPACE=16 VSPACE=10>

Message effectiveness can be said to eq substance + style. Poorly
formatted messages that require a lot of extra effort to read are
not as likely to be read as ones that are carefully presented.

Have to remark that there are those of us who love the command line
but don't plan on completely giving up our mouse and our GUI just
yet. The reason I make that statement has nothing to do with OSs or
inflamatory OT debates except to observe that more Windoze users
are (duh) more acclimated to doing things with the gui than at a
prompt. As I just said I am not interested in engaging in
judgemental debates about THAT, but i think there's a segment of
the monks out there (present or future) who would appreciate the
comfortable-ness of what I propose here, find it congenial, and
adjusted to their way of doing things. OTOH, Maybe i am wrong about
that but what does it matter.

So this snippet is about using a point-and-click means of rapidly
formatting text for entry into the kind of PerlMonks-site browser
entry field that I am using right now. It is Win32-specific. The
Windoze Explorer guishell allows one to right-click and create a
new shortcut. Normally a shortcut points to an existing file
somewhere on the filesystem, of course. The shortcut created in
order to use this Perl I am presenting isn't pointing to anything,
however (except the Perl interpreter). It is a one-liner IOW.
It is a form of the ordinary kind of copy-paste operation most
Monks perform (I assume) many times a day, but with the extra step
of double-clicking a (hopefully very easily accessible, keeping a
special Explorer window view open all the time on the Desktop is
one the points that make this a time-saver) "active" shortcut that
unleashes the power of Perl on the contents of the clipboard,
replacing what the user placed on it with same, but now in
HTML-ized form.

The code in the snippets goes in the field "shortcut" in the
Properties box of the "shortcut-filters" as I am calling these
little pieces of Perl code. In order to work the user must have the
module Win32::Clipboard (ppm to get it if you don't have it) and
uses HTML::FromText to do the magic.

Caution: Needless to say, these one-liners must be pasted into the
appropriate field as one-liners regardless of how they got
wrapped when displayed in the reader's browser rendering of this
Perl Monks node.

Replies are listed 'Best First'.
RE: Perl-Win32
by chromatic (Archbishop) on Jul 04, 2000 at 04:03 UTC
    That's impressive code... but I just use the <CODE> tag around code I include. :)

    (More tips can be found at Site How To.)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-03-19 10:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found