Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The few programmatic hacks in this book run on the command line (that's the Terminal for Mac OS X folks, and the DOS command window for Windows users). Running a hack on the command line invariably involves the following steps:
Type the program into a garden-variety text editor: Notepad on Windows, TextEdit on Mac OS X, vi or Emacs on Unix/Linux, or anything else of the sort. Save the file as directed—usually as scriptname .pl (the pl bit stands for Perl, the predominant programming language used in Mind Performance Hacks).
Alternately, you can download the code for all of the hacks online at http://www.oreilly.com/catalog/mindperfhks. There you'll find a zip archive filled with individual scripts already saved as text files.
Get to the command line on your computer or remote server. In Mac OS X, launch the Terminal (Applications→Utilities→Terminal). In Windows, click the Start button, select Run..., type command, and hit the Enter/Return key on your keyboard. In Unix...well, we'll just assume you know how to get to the command line.
Navigate to where you saved the script at hand. This varies from operating system to operating system, but usually involves something like cd ~/Desktop (that's your Desktop on the Mac).
Invoke the script by running the programming language's interpreter (e.g., Perl) and feeding it the script (e.g., scriptname .pl), like so:
$ perl scriptname.pl
Most often, you'll also need to pass along some parameters—your search query, the number of results you'd like, and so forth. Simply drop them in after the script name, enclosing them in quotes if they're more than one word or if they include an odd character or three:
$ perl scriptname.pl '"much ado about nothing" script' 10
The results of your script are almost always sent straight back to the command-line window in which you're working, like so:
$ perl scriptname.pl '"much ado about nothing" script' 10
1. "Amazon.com: Books: Much Ado About Nothing: Screenplay ..."
[http://www.amazon.com/exec/obidos/tg/detail/-/0393311112?v=glance]
2. "Much Ado About Nothing Script"
[http://www.signal42.com/much_ado_about_nothing_script.asp]
...
|
To prevent the output from scrolling off your screen faster than you can read it, on most systems you can pipe (redirect) the output to a little program called more:
$ perl scriptname.pl | more
You'll also sometimes want to direct output to a file for safekeeping, importing into your spreadsheet application, or displaying on your web site. This is as easy as:
$ perl scriptname.pl > output_filename.txt
And to pour some input into your script from a file, simply do the opposite:
$ perl scriptname.pl < input_filename.txt
Don't worry if you can't remember all of this; each programmatic hack has a "Running the Hack" section that shows you just how it's done.
|