in reply to if/while/else problem

The else is being applied to your while statement, not your if. Try:
if ( -s file ){ while(<MYINPUTFILE>) { my($line) = $_; chomp($line); print FILE2 "$line\n"; print FILE2 "you need to do this\n"; print FILE " \n"; } } else { print FILE2 "There is nothing to do\n"; }

Replies are listed 'Best First'.
Re: if/while/else problem
by ddrew78 (Beadle) on Mar 25, 2009 at 18:57 UTC
    Thanks for the suggestion, but it still prints my 'else' even when the 'if' should have been processed instead.
      Then there must be confusion with file. How about something like this?
      use warnings; use strict; my $in = 'file' my $out = 'file2'; open my $OUT, '>', $out or die $!; if (-s $in) { open my $IN, '<', $in or die $!; while (<$IN>) { my $line = $_; chomp $line; print $OUT "$line\n"; print $OUT "you need to do this\n"; print $OUT " \n"; } } else { print $OUT "There is nothing to do\n"; }