How Perl Saved my Day
Previous First Next

Using MacPerl

The MacPerl application includes a simple editor, with which you can write and edit your Perl scripts. The Alpha Text Editor offers, among others, a Perl mode with syntax coloring, interaction with MacPerl, and many more features. Perl scripts can be saved as applications (Runtime Version) and Droplets: choose Save As... in the File menu of MacPerl and select the appropriate type. Drop the text file you want to manipulate onto the Droplet, and presto! For this to work you must read -- in your Perl script -- data from standard input. Use the following example (a very simple word counter) to test the Droplet method.
#!perl
%words = ();
while (<>) {
 tr/A-Z/a-z/; s/,/ /g; s/\./ /g; s/\{/ /g; s/\}/ /g; s/`/ /g; 
 s/\=/ /g; s/\</ /g; s/\>/ /g; s/\\/ /g; s/\%/ /g; s/\[/ /g; s/\]/ /g;
 s/\(/ /g; s/\)/ /g; s/-/ /g; s/"/ /g; s/\// /g; s/^\s+//; s/\s+$//;
 @wrds = split /\s+/;
 foreach $word (@wrds) { $words{$word}++; }
}
foreach $word (sort keys %words) {
 print "$word ==> $words{$word}\n";
}
Documentation is in the POD format. You can view POD files (ending in pod) with the application Shuck: start Shuck (it resides in the same folder as MacPerl) and select an entry from the Go menu, or open the POD file using the File:Open dialog.

Previous First Next
10.12.1998 Michael Gfeller