"for" for aliasing

TorgoX on 2002-02-22T18:34:24

Dear Log,

My for trick of the day, with HTTP::Response objects:

  for my $c (${ $response->content_ref }) {
     $c =~ ...stuff...;
     $c =~ ...stuff...;
     $c =~ ...stuff...;
  }


Why not use $_?

pne on 2002-02-25T07:56:47

Why not use $_? That way you can leave off all the $c =~ bits. Just use for(...) instead of for my $c (...).

Re:Why not use $_?

TorgoX on 2002-02-25T18:30:39

well, the actual block in the foreach block involved more stuff going on, and calls to different subs. And I'm never happy calling subs when I have something important in $_ -- because if the subs later are rewritten to incidentally clobber $_, I'll have a hard time figuring out the resulting bug. And I'm just not that big into assigning/aliasing to $_ in general, except for tiny tiny things like:
for($k,$v) {tr/\cm\cj//d; s/^\s+//; s/\s+$//; }