Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

TorgoX (1933)

TorgoX
  sburkeNO@SPAMcpan.org
http://search.cpan.org/~sburke/

"Il est beau comme la retractilité des serres des oiseaux rapaces [...] et surtout, comme la rencontre fortuite sur une table de dissection d'une machine à coudre et d'un parapluie !" -- Lautréamont

Journal of TorgoX (1933)

Friday February 22, 2002
01:34 PM

"for" for aliasing

[ #3045 ]
Dear Log,

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

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

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Why not use $_? That way you can leave off all the $c =~ bits. Just use for(...) instead of for my $c (...).
    --

    -- 
    Esli epei eto cumprenan, shris soa Sfaha.
    Aettot ibrec epesecoth, spakhea scrifeteis.

    • 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+$//; }