Superdeluxe Automatic portmanteaus
June 18, 2007 1:50 AM   Subscribe

I want to make a couple of lists . It's a pretty simple format, but I have no idea how to go about it.

Here's the format I'm going for: I need to make portmanteaus. I want put in two source lists, of words or word parts, and come out with every possible portmanteau they will make. Here's an example, as that will probably help (no, this is not the real source data).
List A:

List B:


I need the output to be a text file, and I'm open to pretty much any solution that's easily automated. I have access to MS Office (on both systems), a PC runnning WinXP, and a Mac running OSX and Automator, but nothing else relevant (I don't think). I have no programming experience (no quick but messy way, sorry, as i'm up to about 100 words/wordparts on each list, and that's way too much to output manually.)

So how do I do it?
posted by The Esteemed Doctor Bunsen Honeydew to Computers & Internet (6 answers total) 1 user marked this as a favorite
Best answer: #!/usr/bin/perl
use warnings;
use strict;

my @lista = qw/Super Mega Ultra/;
my @listb = qw/awesome cool deluxe/;
foreach my $b (@listb) {
foreach my $a (@lista) {
print "$a$b\n";

Save the above as a file in your home directory on os x, open (in Applications/Utilities. run the command:

perl > output.txt; open -t output.txt

tada, output appears in TextEdit.
posted by singingfish at 2:02 AM on June 18, 2007

or if you are familiar with Excel put one list across the top, the second in column A, and concatenate.
posted by b33j at 2:04 AM on June 18, 2007

the bits between qw// can be separated by newlines or whatever by the way so you can copy and paste them into your file whatever way you like. basically it assigns each bit of text separated by whitespace to an item in a list.
posted by singingfish at 2:04 AM on June 18, 2007

I would definitely use excel.

i've used the answers in this askme comment several times.
posted by misanthropicsarah at 7:17 AM on June 18, 2007

Best answer: I put a very basic macro together for Excel. Probably not the most efficient of doing this code, and almost 100% not the most efficient way of solving the problem (it currently requires you to past each list into a separate excel column) but I was on a telecon and had some time to kill. Figured I'd post it here in case you didn't want the much-nicer-looking perl version. I commented it as best I could; maybe someone will get something out of it... If I make any other updates, I'll post.

In the code below:
"preword" = the left half of a complete word
"postword" = the right half of a complete word

Sub combine()

prewordCol = "A"     'This is the column letter the preword is in
postwordCol = "B"    'This is the column letter the postword is in
resultCol = "C"      'This is the column letter the combined words are in
resultRow = 1        'This is the starting row for the result column
prewordStartRow = 1  'This is the starting row for the preword column
postwordStartRow = 1 'This is the starting row for the postword column
prewordCurrentRow = prewordStartRow   'initialize the startrow = current row for the beginning
postwordCurrentRow = postwordStartRow 'initialize the startrow = current row for the beginning

curPreword = Range(prewordCol & prewordStartRow).Value    'Save the first preword
curPostword = Range(postwordCol & postwordStartRow).Value 'Save the first postword

'The "While" loops below basically say:
'Pick the preword; if it's blank, then you're at the end of the list (and you're done).
'If it's not blank, then pick the postword; if it's blank, then you're at the end of
'the list, and you go to the next preword. If not, you make the combined word and
'print it in the appropriate place

While (curPreword <> "")
    While (curPostword <> "")
        Range(resultCol & resultRow).Value = curPreword & curPostword 'Combines the words
        postwordCurrentRow = postwordCurrentRow + 1 'goes to next postword
        resultRow = resultRow + 1 'goes to next row to print results
        curPostword = Range(postwordCol & postwordCurrentRow).Value 'looks up next postword
    prewordCurrentRow = prewordCurrentRow + 1 'goes to next preword
    postwordCurrentRow = postwordStartRow 'goes back to first postword
    curPreword = Range(prewordCol & prewordCurrentRow).Value 'looks up next preword
    curPostword = Range(postwordCol & postwordCurrentRow).Value 'looks up first postword

End Sub

posted by inigo2 at 8:49 AM on June 18, 2007

Response by poster: Thanks so much, guys!
posted by The Esteemed Doctor Bunsen Honeydew at 12:26 PM on June 18, 2007

« Older Sexy Havens for Sophisticated Silver Surfers   |   Removing metallic stain from sink Newer »
This thread is closed to new comments.