#!/usr/bin/perl $key = uc(shift || "C"); $mode = lc(shift || "major"); @notes = qw(A A# B C C# D D# E F F# G G# A A# B C C# D D# E F F# G G#); %modes = ("major", -1, "ionian", -1, "dorian", 0, "phrygian", 1, "lydian", 2, "mixolydian", 3, "aeolian", 4, "locrian", 5); @steps = qw(2 2 1 2 2 2 1); $notematch = join "|", @notes; if (($key !~ /($notematch)/) || !(exists $modes{$mode})) {die "Invalid key or mode!\n"} while ($notes[0] ne $key) { push(@notes, shift(@notes)); } for (0 .. $modes{"$mode"}) { push(@steps, shift(@steps)); } unshift(@steps, 0); foreach $i (@steps) { $index += $i; print $notes[$index] . " "; }