in reply to Use of uninitialized value

Declaration isn't the same as initialisation. For example: my $fred; $fred is declared but has not been given an initial value.

Update: If you ensure indentation matches scope it might be easier to see the scope of your variables. In this case the declarations are inside the while loop and the line producing the error is not.

One world, one people

Replies are listed 'Best First'.
Re^2: Use of uninitialized value
by kevyt (Scribe) on Mar 14, 2012 at 02:33 UTC
    I have a similar question. I have tried my $filesize = 0; and  my $filesize = -s $$file; and I am getting the same warning only when the file size is 0. I have searched but I have not found anything useful. Use of uninitialized value $filesize in numeric ne (!=) Can you please help?
    $output_file = 'output_file'; backup_the_data(\$output_file); sub backup_the_data { my ($file) = @_; my $filesize = 0; # my $filesize = -s $$file; $filesize = -s $$file; if ($filesize != 0){ copy($$file, $$file . '_backup'); } }
      This worked.
      if ($filesize){ copy($$file, $$file . '_backup'); }