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 ]

inkdroid (3294)

inkdroid
  (email not shown publicly)
http://www.inkdroid.org/
AOL IM: inkdroid (Add Buddy, Send Message)
Yahoo! ID: summe_e (Add User, Send Message)
Jabber: inkdroid

inkdroid is a person, not a robot. however, inkdroid likes ink. inkdroid likes perl too.

Journal of inkdroid (3294)

Wednesday November 06, 2002
03:56 PM

loop

[ #8807 ]

Peeking over petdance's shoulder I spied this gem:

s/a/z/g for @array;

I guess this sort of loop might be old hat, but I'd never seen it before.

Ahhh, Perl5....

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.
  • # TIMTOWTDI :)
    tr/a/z/ for @array;

    Those sorts of loops always seem to mess with my mind though, and eventually I want to add another statement, so I always end up using the more common block form.

    foreach ( @array )
            {
            warn "Working on [$_]\n" if $Debug;
            tr/a/z/;
            warn "\tnow it is [$_]\n";
            }

    print() is the best debugger ever invented. :)

    Various people have tried to conv
  • The reason I wrote it as

    s/-/ /g for @array;

    instead of

    for ( @array ) {
        s/-/ /g;
    }

    was not to save keystrokes, but to put the interesting part of the code first. I think of how I'd say it in English:

    Change any dashes to spaces throughout the list

    instead of

    Throughout the list, change any dashes to spaces

    I think about that a lot. That's why I like the "open or die" metaphor instead of what I see as entirely backwards "die unless open".

    --

    --
    xoa