in reply to interchanging variables the tough way

How about an unnamed sub (in the spirit of TMTOWTDI):
$a=1,$b=2,$c=3,$d=4,$e=5; ($a,$b,$c,$d,$e) = sub {push@_,shift;return@_}->($a,$b,$c,$d,$e); print "\$a=$a,\$b=$b,\$c=$c,\$d=$d,\$e=$e\n";
It will probably perform worse than the other suggestions though...

/brother t0mas

Replies are listed 'Best First'.
interchanging variables the tough way
by agoth (Chaplain) on Aug 31, 2000 at 13:39 UTC

    ++ for amusement value, nice one :-)

RE (tilly) 1 (possibilities): interchanging variables the tough way
by tilly (Archbishop) on Aug 31, 2000 at 14:43 UTC
    With a sub you can actually stop having to retype the list two times. Which is a nice feature:
    $a=1,$b=2,$c=3,$d=4,$e=5; &rotate($a, $b, $c, $d, $e); print "\$a=$a,\$b=$b,\$c=$c,\$d=$d,\$e=$e\n"; sub rotate { my $temp = $_[0]; foreach (0..($#_ - 1)) { $_[$_] = $_[$_+1]; } $_[-1] = $temp; }
    OK, this is definitely slower, but you see the point.
      Looking at this bugs me.

      Manipulating your input arguments this way works, but the side-effects can surprise and amaze. I would not do this lightly.

      My overall feeling is that if you feel the need to rotate your data, you should have an array rather than a list of variables. Then you could

      push @array, shift @array;
      much faster, without resorting to nasty side-effects.

      Generally when I see myself wanting to resort to "bad" techniques like side-effects, I take that as a danger sign and go looking for a more fundamental mistake in my code...