in reply to Re: perl doesn't like variable
in thread perl doesn't like variable

You need to declare the variable. Try:

my $counter = 0;

Why? He is properly declaring his variable to be a package global, and that is perfectly legit under strictures. It would be a mistake to try to also declare it to be a lexical variable, as that would create two separate variables.

His problem is that he initialized $counter before declaring it. Here is his code:

$counter = 0; use vars qw($counter);

The proper sequence of events is to declare the variable, and then start using it (or initialize it), like this:

use vars qw($counter); $counter = 0;

HTH.


Dave

Replies are listed 'Best First'.
Re^3: perl doesn't like variable
by jbware (Chaplain) on Oct 03, 2004 at 18:17 UTC
    Good catch. Chalk that up to tunnel vision on my part. I saw the usage w/o declaration and didn't even look any further.

    -jbWare