How to Run the Hacks !

The programmatic hacks in this book run either on the command line (that’s Terminal for M ac O S X folk, DO S command window for Windows users ) or as C GI scripts dynamic pages living on your web site, accessed through your web browser. Command-Line Scripts Running a hack on the command line invariably involves the following steps : 1. Type the program into a garden-variety text editor: Notepad on Windows , TextEdit on M ac O S X, vi or Emacs on U nix/Linux, or anything else of the sort. Save the file as directed usually as s criptname.pl (the pl bit stands for Perl, the predominant programming language used in Google Hacks ). Alternatively, you can download the code for all of the hacks online at http://www.oreilly.com/catalog/googlehks2, a ZIP archive filled with individual scripts already saved as text files . 2. Get to the command line on your computer or remote server. In M ac O S X, launch the Terminal (Applications Utilities Terminal). In Windows , c lick the Start button, select Run…, type command, and hit the Enter/Return key on your keyboard. In Unix .well, we’ll jus t assume you know how to get to the command line. 3. Navigate to where you saved the script at hand. T his varies from operating system to operating system, but usually involves something like cd ~/Desktop (that’s your Desktop on the M ac ). 4. Invoke the script by running the programming language’s interpreter (e.g., Perl) and feeding it the script (e.g., s criptname.pl) like so: $ perl scriptname.pl 5. Most often, you’ll also need to pas s 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 6. T he 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]

The bit signifies that we’ve cut off the output for brevity’s sake. 7. To s top output s c rolling off your screen faster than you can read it, on most systems you can “pipe” (read: redirect) the output to a little program called more: $ perl scriptname.pl | more Hit the Enter/Return key on your keyboard to s c roll through line by line, the space bar to leap through page by page. You’ll also sometimes want to direct output to a file for safekeeping, importing into your spreadsheet application, or displaying on your web site. T his is as easy; refer to the code shown next. $ perl scriptname.pl > output_filename.txt A nd to pour some input into your script from a file, s imply do the opposite: $ perl scriptname.pl < input_filename.txt Don’t worry if you can’t remember all of this ; each hack has a “Running the Hack” section, and some even have a “T he Results ” section that shows you jus t how it’s done

We will be happy to hear your thoughts

Leave a reply