in reply to Using aliases in for loops or not?

First off, let's get one thing out of the way: @$record[0] is just horrible. Never use an array slice if you want an array element, that's just plain wrong. $$record[0] is probably what you want. But doesn't $record->[0] look much better?

As for using variables to iterate over an array or using the implicit $_, that's actually debateable. If you're using $_ downstream via regex matching (conveniently done as /.../ as opposed to $record =~ /.../), using the implicit iterator saves some keystrokes. But for all other purposes, I find named iterator variables easier to read. YMMV, of course.

Replies are listed 'Best First'.
Re^2: A question for the enlightened.
by jkva (Chaplain) on Feb 17, 2005 at 09:20 UTC
    Thanks for the reply.
    Uh, "YMMV"? ;)

    I was under the impression that I now used a variable ($record) while it was not needed. Which is memory allocation while not needed, which is inefficient. Or am I wrong on this point? I *do* agree that it is more readable though.

    Regards,

    -- Detonite

      Before saying "it's inefficient", did you benchmark it?
        I am unfamiliar with script benchmarking, thus no, but thanks for the heads-up. But it feels to me like renting two trucks to haul stuff, while you only need one. The speed difference will probably not be visible, but I myself consider it sloppy.
        It's like declaring an Int32 while you need is Int16.