2009/1/31 Rob Canning <address@hidden>:
#!/usr/bin/perl
sub InsertNotes {
my ($num, $form, @notes) = @_;
my ($output, @temp);
while (@notes) {
(@temp[0..$num-1], @notes) = @notes;
$output .= sprintf $form, (@temp);
}
return $output;
}
my @list = qw"a b c d a b c d a f cis d aes b c d g b c d a bes c dis c c c d a e
c d a b c d";
my $format = "%s''4\\pp r16 %s'4\\accent %s''1 %s'''4 r8 %s''4\\mf \\accent %s8
\\staccato\n";
print InsertNotes(6, $format, @list);
what i would like would be numbered variables (%s[1-n]) so i can
repeat/recall certain elements within the script like this:
like this (quasi-code):
my $format = "%s1''8 r16 %s1'4 %s2''1 %s3'''4 r8 %s3''4 %s4''8";
The code is using the sprintf function, you can see how this works
with the command perldoc -f sprintf. What printf needs is a format
string and a list of variables to substitute into the string. Your
quasi-code is close to being correct, you can follow any of the
format strings (in out case %s) with a format parameter index.
The format parameter index is 1$, 2$, etc. i.e. %s1$, %s2$
my $format = "%s1$''8 r16 %s1$'4 %s2$''1 %s3$'''4 r8 %s3$''4 %s4$''8";
If you're going to do that then you'll need to alter the number that
you pass to the InsertNotes function or you'll be throwing
entries from the note array.
also would it be possible to incorperate a second variable reading from a
second list? %B
my $format = "%sA1''%sB1 r16 %sA1'%sB2 %sA2''%sB1 %sA3'''%sB3 r8 %sA3'' %sB2
%sA4''"%sB4;
No, not directly. you would have to interleave the values from the
separate arrays yourself before you called the sprintf function.
I've attached a file with some ides rob3.pl
also
to read from a list
my @list = qw"a b c d a"
is something like this possible?
my @list = qw"mynotelist.txt"
see rob4.pl
HTH
If you want to learn perl, I recommend learning perl by O'Reilly.
andrew