Re: What's being thrown away?



Mathew Snyder wrote:
In the following snippet of code I'm getting the "useless use of a private
variable in a void context" error. It is at line 64 which is the closing brace
for the for loop.

for ($count; $count < 7; $count++) {
^^^^^^
$count is in a void context there. Either:

for ( my $count; $count < 7; $count++ ) {

Or:

for ( $count = 0; $count < 7; $count++ ) {

etc.

But it doesn't look like you are using $count inside the loop anyway so why
not just:

for ( 0 .. 6 ) {

And if you *really* need $count then:

for my $count ( 0 .. 6 ) {


if ($day == '01') {

You are using a numerical comparison on a string. Either:

if ( $day == 1 ) {

Or:

if ( $day eq '01' ) {



John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
.



Relevant Pages

  • Re: commify_series script in cookbook page 94
    ... This relies on ';' being true, and uses 'and' in void context. ... problem with it then you have a problem with many Perl idioms such as ... or, rather, it would work but wouldn't exit from the loop ...
    (perl.beginners)
  • Re: commify_series script in cookbook page 94
    ... This relies on ';' being true, and uses 'and' in void context. ... or, rather, it would work but wouldn't exit from the loop ... not a traditional separator character. ...
    (perl.beginners)
  • Re: Whats being thrown away?
    ... I replaced the for loop with a while loop and it eliminated the problem. ... Mathew Snyder wrote: ... variable in a void context" error. ... push @days, $day; ...
    (perl.beginners)
  • Re: Whats being thrown away?
    ... On 12/31/2006 05:04 AM, Mathew Snyder wrote: ... variable in a void context" error. ... It is at line 64 which is the closing brace ... for the for loop. ...
    (perl.beginners)
  • Re: make(1) is broken?
    ... Results for VAR2 seems quite strange for me. ... The second closing brace doesn't belong to ... why does it work within the for loop? ... Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing ...
    (freebsd-hackers)