in reply to "use strict" and undeclared variables

omfg.. yours is the funniest post i've seen in a long time..

It's because @row is not being declared.. that is.. it's not being told 'row exists in this area of the program'.

keep using strict! Trust the strict- Strict is good- Strict is your friend. It's your girlfriend who loves you but won't put up with any of your 5h1+.

If she whines and complains.. it means you need to stop that- or your code 'looks' like it's working.. but it's *not*.

Like moritz suggested, this should work:

while ( my @row = $sth->fetchrow_array ) { print "@row\n"; }

Again, what is happening is that you don't say anywhere 'my @row'.

You could also have done this.. (althought bad form and possibly buggy):

my @row; while ( @row = $sth->fetchrow_array ) { print "@row\n"; }

updateikegami suggests these snipplets are essentially the same, and that the second is not bad form or possibly buggy. And it was the # on strict that cracked me up. It's like when my two year old goges 'mommy i'm hot' so she pours a glass of cold organge juice all over herself and says 'now everything is great!'- that it's funny doesn't mean you have ill feelings for the situation.

Replies are listed 'Best First'.
Re^2: "use strict" and undeclared variables
by mjscott2702 (Pilgrim) on Oct 11, 2007 at 20:16 UTC
    No need to be rude about it - as poster stated, they are a newbie to Perl. After all, asking questions, after having at least made an attempt, is how people LEARN.
Re^2: "use strict" and undeclared variables
by chrism01 (Friar) on Oct 12, 2007 at 00:37 UTC
    What's bad/buggy about the latter? I always do that (hangover from C I guess).
    I prefer not to mix declarations and usage. Also, it means I can comment the declarations...

    Cheers
    Chris

      As a rule of thumb, you should try to restrict the scope of a variable as much as possible. The former restricts @row life to the while block, while the other goes beyond. Anyway, I wouldn't classify this neither as "bad" nor as "buggy".

      Flavio
      perl -ple'$_=reverse' <<<ti.xittelop@oivalf

      Io ho capito... ma tu che hai detto?
        Anyway, I wouldn't classify this neither as "bad" nor as "buggy"

        I personally believe "error prone" may be more appropriate. Ain't it?

        Exactly.
        I was thinking of a more complex loop, and a more complex origin of @row's content. The possibility of contamining the array through some buggy code elsewhere, etc.
        But I didn't explain that more thoroughly- and it was perceived I came accross as rude :-( Sigh.