kanyaya has asked for the wisdom of the Perl Monks concerning the following question:

I have designed a script to measure the distance between 2 specific points. The code is currently working for only the 1st item but the document contains around 100 different items and I would like to calculate the distance for all 100 if possible.

my $xyz = $document->M->Item(1);

I am wondering if there is any way to change the item number in the brackets as part of a loop so that the script runs again but using every item from 1 to 100. I am pretty new to coding so haven't had much luck so far in getting this to work. Thank in advance.

Replies are listed 'Best First'.
Re: Creating a loop for all items in a document
by hippo (Archbishop) on Jan 05, 2020 at 14:17 UTC

    If you just want a loop then maybe this is all you need?

    for my $itemno (1 .. 100) { my $xyz = $document->M->Item($itemno); # More code here }

    See foreach loops in perlsyn for more info.

      Thanks for your help. I will try this today.