in reply to looping efficiency

You can do it like this:
A string range can be used instead of numeric values.
use strict; use warnings; foreach my $num_string ('0000'...'9999') { my($i,$j,$k,$l) = split (//,$num_string); print "i=$i j=$j k=$k l=$l\n"; }
Abbreviated printout
i=0 j=0 k=0 l=0 i=0 j=0 k=0 l=1 i=0 j=0 k=0 l=2 i=0 j=0 k=0 l=3 i=0 j=0 k=0 l=4 i=0 j=0 k=0 l=5 i=0 j=0 k=0 l=6 i=0 j=0 k=0 l=7 ..... i=9 j=9 k=9 l=3 i=9 j=9 k=9 l=4 i=9 j=9 k=9 l=5 i=9 j=9 k=9 l=6 i=9 j=9 k=9 l=7 i=9 j=9 k=9 l=8 i=9 j=9 k=9 l=9

Replies are listed 'Best First'.
Re^2: looping efficiency
by AnomalousMonk (Archbishop) on Dec 30, 2020 at 01:14 UTC
    my($i,$j,$k,$l) = split (//,$num_string);

    I haven't done any Benchmark-ing (and won't), but unpack might be faster than split:
        my($i,$j,$k,$l) = unpack '(a)4', $num_string;


    Give a man a fish:  <%-{-{-{-<

      Yes, I also suspect that unpack is faster. However, I have doubts that would make a difference. Of more importance perhaps is why these individual digits need to be known in the first place? I have no idea. Maybe the OP can clue us in to what this exercise is for?
      Considering it's Perl, split vs unpack seems irrelevant.

      -QM
      --
      Quantum Mechanics: The dreams stuff is made of