open my $data, '+<', $INFILE1 or die "can't open\n$INFILE1\n"; while (<$data>) { ...; my ( $data ) = split (',',) ; ... close $data or die "can't close\n$INFILE1\n"; }
Apart from any other problem(s), the $data lexical filehandle you're trying to close is not the one you open-ed and is not a filehandle at all. It is a lexical of the same name that was created as a part of the split statement and that hides or "shadows" the filehandle lexical. Inclusion of the $! error variable in the die expression of the close statement might have alerted you to the fact that it wasn't a filehandle. (See $! in Error Variables in perlvar.)
... if the first column is not empty, then it should print out to the same file ...
The statement
print "$_ \n";
prints to the default filehandle, which I assume would be STDOUT given the code we are shown in the OP. (Update: select can change this default.)
In reply to Re: read file line by line then do something and write to same file
by AnomalousMonk
in thread read file line by line then do something and write to same file
by john.tm
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |