in reply to Re: Perl - Source code review
in thread Perl - Source code review

I assume the curlies are not empty in the original, right? The loop removes the elements from the array one by one starting at the end and stops once there are no more elements to remove. The last element is at the start of the first iteration, before the body of the loop runs and as it is not assigned anywhere it most probably is not processed.

If the curlies were empty and the array was not tie()d, then the line would be equivalent to @LogFileList = ();

The only case in which it would make some sense to use that line with empty curlies would be if

  1. the array was tie()d
  2. removing elements from the tie()d array had some important side-effects
  3. you wanted the side effects to occure starting with the last element

Jenda
Enoch was right!
Enjoy the last years of Rome.

Replies are listed 'Best First'.
Re^3: Perl - Source code review
by Anonymous Monk on Nov 13, 2014 at 10:24 UTC
    I assume the curlies are not empty in the original, right?
    Wrong :)
    If the curlies were empty and the array was not tie()d, then the line would be equivalent to @LogFileList = ();
    Except worse :)  perl -E 'my @ary = (0, 1, undef, 3); while (defined(pop @ary)) {}; say join "|", @ary' Which is probably not what they wanted.
    The only case in which it would make some sense to use that line with empty curlies would be if...
    4. the entire thing is just that bad.

      Ouch, you are right, I am wrong. It only removes the elements up to the first undef. Probably now what was intended either.

      Jenda
      Enoch was right!
      Enjoy the last years of Rome.