This section is now closed for posting code. Please use Cool Uses For Perl instead.

Code Categories
Audio Related ProgramsFTP stuffNT Admin
CGI ProgrammingFun StuffWin32 Stuff
Chatterbox ClientsGUI ProgrammingMiscellaneous
CryptographyHTML UtilityText Processing
Database ProgrammingUtility ScriptsNetworking Code
E-Mail ProgramsWeb StuffPerlMonks Related Scripts


New Code
word twist
on Jun 18, 2007 at 02:48
2 replies by ysth
Based on a popular word game with a similar name on an unnamed ActiveX based site. Given 6 letters, guess all words that can be made from those six letters. Enter "-show" to show all unguessed words for one round, "-new" to start with a new set of letters.

The code was hacked together quite sloppily, but it does what I want it to do.

Creates an umbrello compliant xmi document from a set of classes
on Jun 14, 2007 at 11:06
0 replies by hanspoo
Create an acceptable representation of a perl object model in xmi. By default prints the xmi document in standard output, this can be overwriten with the parameter --out-file. It's based on an umbrello document retouched incrementally. Classes given in command line are fully loaded and are given different treatement than classes just referenced. This automatically sets a scope for recursion. Classes indicated on command line will ve eval'ed. May be you will need to set PERL5LIB. Cardinality is not considered yet. This script is a good starting point, it's dirty, but works.
Surround-inspired Gtk demo
on Jun 09, 2007 at 17:59
0 replies by drench
Since there's been no activity in the GUI programming category for nearly 4 years, maybe it's appropriate that this code is something I wrote in the early 2000s, teaching myself basic Gtk while commuting to and from work. Inspirations: the Atari 2600 "Surround" cartridge and graphics programming on the Apple II and Atari 800, and randomness. Quick notes: the escape key erases the canvas. Other mouse and key events have little effect (try & see), and see the code for some undocumented command-line options (redundant; the whole thing's undocumented, unless you count this). Mainly it was fun to write and kind of fun to watch run.
Code Typesetter
on Jun 02, 2007 at 19:55
2 replies by Minimiscience
For each filename passed as an argument, this script will produce a PostScript file that neatly typesets the text of the original file, complete with a simple header on each page, page numbers, numbering of every fifth line, & long lines broken up with red hyphens. The primary purpose is for printing source code beautifully (for a given value of "beautiful"), though it will work on any kind of ASCII text document, as long as the file name has an extension & there are no backslashes or parentheses in the filename (otherwise, bad things happen).
genpass Password Generator
on Jun 02, 2007 at 01:09
4 replies by munkyeetr
Command line script that can generate multiple random passwords of any length. User can exclude character-types by using command line options. I believe I have handled foreseeable errors, and that the code is well commented. REQUIRED MODULES: Getopt::Long
Contextualized weighted grammar generator
on May 31, 2007 at 23:43
2 replies by raptur
Reads in a directory of corpus files in the format used by the Penn Treebank:

((NP
(ADJP (ADV just) (ADJ another))
(NN perl)(NN hacker)))

finds all the grammar rules demonstrated in the corpus files for a given node, contextualized relative to the local left-sister (or mother if -m is passed). Moreover, it counts how many times each rule is observed, and produces a weighted grammar for the given node only. Designed for exploring the sort of information contained in local context in natural language, and whether there are meaningful clusters of context that improve the accuracy of natural language parsing. For earlier work in this area, see:
Johnson, Mark (1998). The effect of alternative tree representations on tree bank grammars. In D.M.W. Powers (ed.) New Methods in Language Processing and Computational Natural Language Learning, ACL, pp. 39-48.

This is a revised title and description for the earlier post entitled CPCFG_count.pl in response to others' suggestions. This post is otherwise unchanged.

Data type validation using regular expressions
on May 26, 2007 at 16:17
2 replies by Anonymous Monk
This is the first Perl script I ever wrote. Any input to make it better, or do differently (using some existing model, for example) highly appreciated.

The simple perl script proof of concept demonstrated here, performs data type validation on the provided data file. The script creates an output file with bad data attributes substituted by default values. The data type specification and default values are read from a specification file.

Usage example:

Consider sales_payment.dat file:

A|10.50|CC|2006/12/05|10:05:15 2|12A|Cash|2006/12/05|10:12:18 3|100|12 Un|2006/12/05|10:15:23 4|.85|A1|2006/12/05|10:18:00 5|-100|B2|2006/12/05|10:20:00 6||C|2006/12/05|10:22:00 7|100||2006/12/05|10:26:00 8|200|D|2006/02/31|10:32:00 9|2006/02/31|10:33:00 10|400|E|2006/03/40|30:35:00 11|400|F|1234|10:41:AA 10|300|G|2006/02/31|10:05:15
A specification file sales_payment.spec is created; the file contains metadata - data attribute name, attribute data type defined using regular expressions, and default data value that is used when the data file contains bad data - separated by commas (','):
transaction_number,^\d+$,-1 total_basket_amount,^[-+]?[0-9]*\.?[0-9]+$,0 payment_type,^\w$,_Unknown date,(19|20)\d\d[/](0[1-9]|1[012])[/](0[1-9]|[12][0-9]|3[01]),1900/01/ +01 time,^([0-1][0-9]|[2][0-3]):([0-5][0-9]):([0-5][0-9])$,00:00:00
When we run data validation:
unix> perl validate_data_type.pl "sales_payment.spec" "sales_payment.d +at" "sales_payment_out.dat" "sales_payment.log" 50
...the output data file is created:
-1|10.50|CC|2006/12/05|10:05:15 2|0|Cash|2006/12/05|10:12:18 3|100|_Unknown|2006/12/05|10:15:23 4|.85|A1|2006/12/05|10:18:00 5|-100|B2|2006/12/05|10:20:00 6|0|C|2006/12/05|10:22:00 7|100|_Unknown|2006/12/05|10:26:00 8|200|D|2006/02/31|10:32:00 10|400|E|1900/01/01|00:00:00 11|400|F|1900/01/01|00:00:00 10|300|G|2006/02/31|10:05:15
...along with a log file:
Spec File> sales_payment.spec Data In File> sales_payment.dat Data Out File> sales_payment_out.dat Log File> sales_payment.log Max errors: 50 Error 1. Data type error on line: 1, attribute: 1 (transaction_number) Error 2. Data type error on line: 2, attribute: 2 (total_basket_amount +) Error 3. Data type error on line: 3, attribute: 3 (payment_type) Error 4. Data type error on line: 6, attribute: 2 (total_basket_amount +) Error 5. Data type error on line: 7, attribute: 3 (payment_type) Error 6. On the data line: 9, # attributes: 3, do not match # attribut +es in the file specification: 5 Error 7. Data type error on line: 10, attribute: 4 (date) Error 8. Data type error on line: 10, attribute: 5 (time) Error 9. Data type error on line: 11, attribute: 4 (date) Error 10. Data type error on line: 11, attribute: 5 (time) Process completed with: 10 errors Formatted documentation available at: <a href=http://www.dwoptimize.co +m/2007/05/data-type-validation-using-regular.html>www.dwoptimize.com< +/a>
Simple interface to DBI
on May 11, 2007 at 10:47
1 reply by Qiang
I wrote this to avoid writing the same kind of DBI calls in my program. I haven't used this module that much yet. but i would like to hear what your thought to it.
tlu -- TransLiterate Unicode
on May 06, 2007 at 05:11
1 reply by graff
So many unicode characters (and so many ways to represent them), so little time... So, here's a quick and easy way to convert them all into a consistently readable (or programmable) form of your choice. When faced with really bizarre stuff, the one-character-per-line output can be very instructive.

(I was espcially pleased to find that this even works for the "really wide characters" above U+FFFF: the UTF-16 "Surrogate" thing is handled as if by magic, and 'unicore/Name.pl' covers a lot of that "higher plane" stuff.)

Updated to fix regex error (lines 33 and 34) regarding utf-16be option ("ub"). Also, the "Python escape notation" support was added recently, and now I've added mention of that in the POD.

TinyMCE Perl Compressor
on Apr 29, 2007 at 16:41
2 replies by clinton
TinyMCE is an open source cross browser rich text editor from Moxiecode. The TinyMCE Perl compressor gzips all javascript files in TinyMCE to a single streamable file. This makes the overall download size 75% smaller and the number of requests will also be reduced. The overall initialisation time for TinyMCE will be reduced dramatically if you use this script. The TinyMCE Perl compressor project page is at http://hacks.traveljury.com/perl_compressor/