in reply to Processing a dynamic array

"...and while loops don't seem to work either. If i put a number for example x < 900 then the script is executed perfectly but if i leave something like x < links then it doesn't..."

while loop should work, the issue is the condition you give to the while loop (whether you take any sanp shot):

Replies are listed 'Best First'.
Re^2: Processing a dynamic array
by lampros21_7 (Scribe) on Oct 29, 2005 at 16:32 UTC
    thanks pg and merlyn, dont quite understand what you mean pg "the following example simulates your situation by saying that each even number has a link that is its half". I don't mention something like that in my post, could you explain it?Thanks

      That was my fault to make up the link thing ;-) Sometime, you thought you read certain things, but they are not there.

      That's fine. The whole purpose was to simulate your situation: a growing array where the growing eventually stops.

        Hey, i have been trying what pg has recommended but it doesn't seem to work. I have added
        my $first = shift @links; push @links, $first / 2 if (!($first % 2));
        at the end my loop and obviously it gives me the error Argument "http://www.perlmonks.com/" isn't numeric in modulus (%) which makes sense. Then i try just putting
        my $first = shift @links; push @links, $first;
        at the end of my code but that doesn't seem to work either.

        The way i see it, when we shift $first from an array and add it to the end of the array doesn't that mean that $first will be processed again after all the current elements are processed, when we reach that again? I might have the wrong idea for this so could someone please explain? Thanks in advance P.S: The "Argument "http://www.perlmonks.com/" isn't numeric in modulus (%)" is only for reference i havent used the perlmonks website in my loop!!