[sword-devel] perl arrays and usfm2osis.pl
Joachim Ansorg
nospam+sword-devel at joachim-ansorg.de
Sat Jul 5 01:19:36 MST 2008
Hi Daniel,
> @nCR = (a ..z) # Creates the array
> $nCR = @nCR[0]; # Sets the value of $nCR to 0 ("a") at the beginning
> of each file (book)
>
> Then when I am creating cross-references it prints:
>
> n="$nCR"
>
> and then after the note is created I have this at the end of the sub:
>
> $nCR ++;
>
> so that the next cross-reference is b then c, etc. I want to cycle
> through the array from @nCR[0] to @nCR[25] and then return to @nCR[0].
> In other words the 27th cross-reference in a book should be n="a" not
> n="aa".
$nCr is not a reference into the array, it contains the value 'a' after the
first assignment. Then you call the operator ++ on that value. Perl has some
builtin magic for that operator (man perlop) for strings. So this is not what
you want.
This code cycles through the array nCr several times:
@nCr = (a..z);
for my $i (0..100) {
print $nCr[$i % scalar(@nCr)] . " ";
}
Hope that helps,
Joachim
--
<>< Re: deemed
www.bibletime.info
More information about the sword-devel
mailing list