redefine warning(Eval) in perl

Here is my perl Program:

#!/usr/bin/perl -w

my $a="sam";
my $b="ste";
my $c="abcdef";
my $d=931;

$str="
@<<<<< @>>>>>>>>>> @|||||||||||||||||||| @#########
\$a,\$b,\$c,\$d
.";

open(FILE,">abc.txt");

$temp="format FILE = $str";
eval $temp;
write FILE;
print FILE "\n\n";

close(FILE);

$str="
@<<<<< @>>>>>>>>>>
\$a,\$b
.";

$a="Sum";
$b="Ste";

open(FILE,">>abc.txt");

$temp="format FILE = $str";
eval $temp;

write FILE;
close(FILE);

When i execute this program i get "Format FILE redefined at (eval 2) line 1." warning message. Could anybody explain why i get this warning and how to do away with this. Output of the program is although, correct.

Because you are redefining the FILE format ...? Use a different file handle in the second part to avoid this (replace FILE with OTHER. or whatever).

If you really are writing to the same file all the time, can't you use a multi-line format to put all of the stuff in one big write?

Or, see the warnings(3p) manual page for an introduction to disabling selected warnings. Basically, you could put "no warnings" in the second eval to get rid of this warning; you can have more fine-grained control if you require it (probably a good idea, but read up on the topic if interested).

I don't really understand why you need to "eval" these things, but that's just a side remark, and doesn't affect this particular problem.

well, The code which i listed out just shows part of my program. I have a subroutine which contains variation of this code and the subroutine is called hundreds times. Therefore i can't use different names for file handler and moreover i am creating Template using format dynamically,that's why i need to redefine the file handler. I feel using "no warning" is like getting around the problem rather than walking over it.

Maybe you can avoid using the raw format definition. There's a low-level formline function which allows you to access the format facility without actually involving an actual format, although it's a bit tricky to use.