in reply to Multiple assignment in Perl

($a, $b) = ($b, $a + $b);

Replies are listed 'Best First'.
Re^2: Multiple assignment in Perl
by rnaeye (Friar) on Jul 23, 2018 at 00:23 UTC
    That is embarrassing for me! It was the first thing I tried; it did not work for me at the time. I must have made a typo, etc. Thank you.

      Maybe on your first attempt, you put an extra my in front of it? That would cause issues because it would declare two new variables within the while loop which would mask the old variables.

      Also, $a and $b are really bad variable names to choose in Perl. There are special variables with these names used by sort so using them for other stuff can occasionally cause issues. $x and $y would be fine, as would more meaningful variable names.

        Thanks for the tip on variable usage.