From: Conrad Schneiker Date: 2001-02-03T06:10:58+09:00 Subject: [ruby-talk:10289] Ideas for Ruby (A Python/Perl phrasebook) FYI: This is an interesting link mentioned on comp.lang.python recently. http://starship.python.net/~da/jak/cookbook.html # A Python/Perl phrasebook # # By Jak Kirman (jak@cs.brown.edu) # # This phrasebook contains a collection of idioms, various ways of # accomplishing common tasks, tricks and useful things to know, in # Perl and Python side-by-side. I hope this will be useful for people # switching from Perl to Python, and for people deciding which to # choose. The first part of the phrasebook is based on Tom # Christiansen's Perl Data Structures Cookbook. # # I have only been working on this for a short time, so many of the # translations could probably be improved, and the format could be # greatly cleaned up. # # I will get the data-structures cookbook translated first and then go # back to clean up the code. Please send me any comments or # suggestions. # # Also, since I have been using Python for far less time than Perl, # there are certainly idioms I don't know or that I will misuse. [...] # Table of contents # # A Python/Perl phrasebook # Table of contents # Simple types # Strings # Creating a string # Quoting # Interpolation # Modifying a string # Importing # Common tasks # Reading a file as a list of lines # Some general comparisons # Lists of lists # Lists of lists: preliminaries # requires/imports # Declaration of a list of lists # Generation of a list of lists # Reading from a file line by line # Reading from a file in one go # Filling a list of lists with function calls # Filling a list of lists with function calls, using temporaries # Adding to an existing row in a list of lists # Accessing elements of a list of lists # One element # Another element # Printing a list of lists # Print a list of lists using references # Print a list of lists using indices # Print a list of lists element by element # Print a list of lists using map # Print a list of lists using map and anonymous functions # Hashes/dictionaries of lists # Preliminaries # Declaration of a hash of lists # Initializing hashes of lists # Initializing hashes of lists from a file # Reading into a hash of lists from a file with temporaries # Initializing a hash of lists from function calls # Initializing a hash of lists from function calls with temporaries # Append to a list in a hash of lists # Access elements of a hash of lists # Access a single element # Change a single element # Print a hash of lists # Simple print # Print with indices # Print sorted by number of members # Print sorted by number of members, and by name within each list # Lists of hashes/dictionaries # Lists of hashes: preliminaries # Declaration of a list of hashes # Generation of a list of hashes # Reading a list of hashes from a file # Reading a list of hashes from a file without temporaries # Generation of a list of hashes from function calls # Preliminaries # Generation # Generation without temporaries # Adding a key/value pair to an element # Accessing elements of a list of hashes # Printing a list of hashes # Simple print # Print with indices # Print whole thing one at a time # Interface to the Tk GUI toolkit # Preliminaries # Hello world label Conrad Schneiker (This note is unofficial and subject to improvement without notice.)