in reply to Hash versus substitutation efficiency?

A random tip. You are not declaring your loop variables. That practically guarantees that you don't use strict.pm.

I strongly suggest adding

use strict;
to the top of your programs, and then inserting my liberally as in:
foreach my $word ( @termList ) { ... }
Yes, this requires work. But it is worth it to get a significant fraction of your typos automatically caught for you.

Replies are listed 'Best First'.
Re^2: Hash versus substitutation efficiency?
by pg (Canon) on Oct 11, 2004 at 21:50 UTC
    "You are not declaring your loop variables. That practically guarantees that you don't use strict.pm."

    How do you know that he didn't declare his loop variables? also what made you believe that he didn't use strict? His code could be something like this:

    use strict; use warnings; my $i; my @a = (1,2,3); for $i (@a) { print $i; }

    The real point here is that, it is always a better idea to have the smallest possible scope for your variables, so it is nicer to code like this:

    use strict; use warnings; my @a = (1,2,3); for my $i (@a) { print $i; }
      You're right that I don't actually know. But in past instances where I've given this tip, I've had several people tell me privately that they hadn't used strict, and none tell me that I was wrong, they actually were using strict. Therefore I think it very likely that he isn't using strict.

        That's perfectly okay. You did it for a good will, and you are always helpful. I just thought that, in this case, your conclusion was not supported by strong evidence and was logically defected, and it is better to make the right message to everyone.

        In general, use strict is always a very helpful tip.

Re^2: Hash versus substitutation efficiency?
by bwelch (Curate) on Oct 12, 2004 at 15:08 UTC
    Thanks, tilly, that's good advice! I do use strict and warnings in all my code, but since I was just posting code fragments I didn't think to do so.

    Whenever I receive any perl code, before doing anything I run perltidy on the code and add "use strict" and "use warnings". It's easily worth the effort.

      Ideally you're using an editor that does the indenting for you, and your fingers just type my appropriately by habit.