in reply to Re^3: Subroutine to delete one file and copy one file to another
in thread Subroutine to delete one file and copy one file to another

Most of the errors are now resolved after putting the "my" before each variable.
i have few concerns: 1) If the temp file doesnt exist , i need to create one and copy the c +ontents of serverlist.txt in the newly created temp file. 2) If it already exists, i need to delete the contents of that temp fi +le and copy the contents of server.txt into the existing temp file. How this is possible? Any help is highly appreciated. Thanks

Replies are listed 'Best First'.
Re^5: Subroutine to delete one file and copy one file to another
by stevieb (Canon) on Jul 20, 2015 at 22:12 UTC
Re^5: Subroutine to delete one file and copy one file to another
by soonix (Chancellor) on Jul 21, 2015 at 12:48 UTC
    If I understand your problem correctly, then there's no need for the "delete and copy" dance.
    Simply open your tempfile for output and it will automatically get created or truncated.
    You already populated your @outagenodes from the data read from your serverlist. So why don't you simply:
    open(my $tempfh, ">", $tempfile) or die "couldn't open $tempfile: $!"; print$tempfh @outagenodes or die "error when writing: $!"; close $tempfh or die "huh?? - $!";
    BTW I deliberately leave off the space in print$filehandle to remind myself that there's no comma between the file handle and the list...