Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: perl doesn't like variable

by Dietz (Curate)
on Oct 03, 2004 at 14:12 UTC ( #396010=note: print w/replies, xml ) Need Help??

in reply to perl doesn't like variable

Under use strict, your $counter is initialized before it is declared:
$counter = 0; use vars qw($counter);

So you have to declare it (outside of while(<INPUT>)):
my $counter = 0;

Note, that you don't need use vars qw($counter); afterwards.
Otherwise you would declare just another variable called $counter living in the symbol table:
my $counter = 0; # declare and initialize lexical variable use vars qw($counter); # declare global variable living in symbol tabl +e + + $counter = 0; # initialize again, just to show that $counter in 'use v +ars' is not affected print "\$main::counter: $main::counter\n"; # $counter living in symbol + table: not initialized $main::counter = 1; # initialize $counter in symbol table print "\$main::counter: $main::counter\n"; # prints 1 print "\$counter: $counter\n"; # prints 0

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://396010]
[LanX]: Jeez ... the new location for GPW so remote that hotels are cheaper than AirBnB oO
[LanX]: ... and I can get faster to the Dutch PW or French PW ...
LanX ...(by train from Frankfurt)
[LanX]: renting a car could be an option ...
[NodeReaper]: speedboat

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (9)
As of 2018-03-19 11:56 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (239 votes). Check out past polls.