#!/usr/bin/perl use v5.14; use warnings; my @notes = qw/C C# D D# E F F# G G# A A# B C2 C2#/; # List of notes my %notes = map {; $notes[$_] => 12 + $_ * 5 } 0 .. $#notes; # Hash from note name to note start index my @ex = split "\n", <<'EOF'; ----|-\-----------------------------------------------------------------------------+ | } | ----|-/-----------------------------------------------------|----|------------------| |/ 4 | | | | (@) #(@) | ---/|-----------------------------------|----|----|----|----|----|--(@)--|----|-----| / | 4 | | | | | (@) #(@) | | | | -{--|-\------------------|----|----|----|----|--(@)-#(@)------------|----|----|-----| \_|_/ | | | | | (@) #(@) | | ----|\---------|----|----|----|--(@)------------------------------------------------+ |_} | | (@) #(@) (@) #(@) EOF $_ .= ' ' x 80 for @ex; # Append 80 spaces to each line of @ex <>; # Read the first line and ignore it my @song = map { chomp; $notes{$_} } <>; # Song is an array of start indices for my $l (@ex) { # For each line of @ex... print substr $l, 0, 12; # ...print the clef and measure print substr $l, $_, 5 for @song; # ...print each note print substr $l, 82, 3; # ...print the final bar say ''; # ...print a newline }