[sword-devel] perl arrays and usfm2osis.pl

Ben Morgan benpmorgan at gmail.com
Sat Jul 5 01:28:11 MST 2008


You don't really need an array (though it doesn't hurt):

$nCR='a';
for my $i (0..100){
   print "$nCR\n";
   $nCR = 'a' if $nCR++ eq 'z';
}

Also, remember not to use a single = in if statements, as that will do
assignment
 if ($nCR = @nCR[25]) {
will set $nCR to z and thus through the first block which does numeric
addition - so it converts it to a number.

God Bless,
Ben
-------------------------------------------------------------------------------------------
The Lord is not slow to fulfill his promise as some count slowness,
but is patient toward you, not wishing that any should perish,
but that all should reach repentance.
2 Peter 3:9 (ESV)


On Sat, Jul 5, 2008 at 6:19 PM, Joachim Ansorg
<nospam+sword-devel at joachim-ansorg.de> wrote:
> 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
>
> _______________________________________________
> sword-devel mailing list: sword-devel at crosswire.org
> http://www.crosswire.org/mailman/listinfo/sword-devel
> Instructions to unsubscribe/change your settings at above page
>



More information about the sword-devel mailing list