in reply to Array manipulation
$max_count = 100; $counter = 0; while( $counter < $max_count ){ $conter++; print "COUNT = $count" }
You would expect to see:
COUNT = 0 COUNT = 1 ... COUNT = 99
Instead you would see:
And so on until you interupted the program. If this was from a more complex code sample, it may not be obvious at first that you were never incrementing the variable named "counter", but instead another variable named "conter".COUNT = 0 COUNT = 0 COUNT = 0 ...
With strict turned on, the code would look like this:
my $max_count = 100; my $counter = 0; while( $counter < $max_count ){ $conter++; print "COUNT = $count" }
The compilation would fail and you would be informed that there was no variable declared named 'conter'.
The reason for this is that Perl does not have strongly typed variables, which can lead to problems that only manifest themselves at runtime. Using strict is a way to get around some of these problems.
|
|---|