redefine warning(Eval) in perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting redefine warning(Eval) in perl
# 1  
Old 03-25-2008
redefine warning(Eval) in perl

Here is my perl Program:
Code:
#!/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.

Last edited by Yogesh Sawant; 03-25-2008 at 07:48 AM.. Reason: added code tags
# 2  
Old 03-25-2008
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.
# 3  
Old 03-26-2008
Re:

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.
# 4  
Old 03-26-2008
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Perl error : perl: warning: Setting locale failed.

This's my problem perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LC_ALL = "en_US.UTF-8", LC__FASTMSG = "true", LC_MESSAGES = "", LC_CTYPE = "en_US.UTF-8", LC_TYPE = "en_US.UTF-8", LANG = "EN_US"... (1 Reply)
Discussion started by: bobochacha29
1 Replies

2. Shell Programming and Scripting

Concatenate rows and redefine range

I'm trying to find a way to concatenate consecutive rows (key is column $1 and $2) if column $5 an $6 are integers and redefine ranges in columns $3&$4 and $5&$6 Unfortunately I'm still learning the very basics so I cannot figure a way of doing this with awk. Input file 15 30 21 21 25.0... (11 Replies)
Discussion started by: alex2005
11 Replies

3. Shell Programming and Scripting

Using the set command to redefine shell variables

so i'm havin a bit of a issue getting set to recognize a value with spaces as a variable. this is what i'm doing: VAR="1 2 4 11 'dogs mouse cars' 50 19 'noise toys' " set -- ${VAR} When i issue a command such as the one below: echo $5 or echo "${5}" i get dog when i... (2 Replies)
Discussion started by: SkySmart
2 Replies

4. Shell Programming and Scripting

Error in eval eval command to print html tags

anyone has any info on why this is complaining??? vivek@vivek-c5e55ef2e ~/TAC $ zoneCounter=1 vivek@vivek-c5e55ef2e ~/TAC $ optUsage1=23% vivek@vivek-c5e55ef2e ~/TAC $ eval eval echo "<th>Zone $zoneCounter </th><th align=\"left\"> \$optUsage$zoneCounter </th>" -bash: syntax error... (13 Replies)
Discussion started by: vivek d r
13 Replies

5. Shell Programming and Scripting

Error in eval eval command to print html tags

anyone has any info on why this is complaining??? vivek@vivek-c5e55ef2e ~/TAC $ zoneCounter=1 vivek@vivek-c5e55ef2e ~/TAC $ optUsage1=23% vivek@vivek-c5e55ef2e ~/TAC $ eval eval echo "<th>Zone $zoneCounter </th><th align=\"left\"> \$optUsage$zoneCounter </th>" -bash: syntax error... (1 Reply)
Discussion started by: vivek d r
1 Replies

6. Shell Programming and Scripting

Perl eval problem

Hello All, I am trying to use perl eval in a complex code and below given is a pseudo code of my logic. Here $result evalutes to empty. Please help.How should I retrieve of $t where $f just hold the name of varaible i.e t $t=10; $f='$t'; $result=eval "\$$f"; print "$result\n"; (3 Replies)
Discussion started by: prasperl
3 Replies

7. Shell Programming and Scripting

Help with perl eval command .....

Hi All, I read the above written code (perl code) in another perl script and evaluates this code for each line of text file,but using exit statement in code make this not to work and i could not get the desired results. However if i use return it works fine. I just need to know why it doesn't... (1 Reply)
Discussion started by: sarbjit
1 Replies

8. Shell Programming and Scripting

Strange result of eval, how does eval really work with ssh?

Hi all, some small script with eval turned me to crazy. my OS is linux Linux s10-1310 2.6.16.53-0.8.PTF.434477.3.TDC.0-smp #1 SMP Fri Aug 31 06:07:27 PDT 2007 x86_64 x86_64 x86_64 GNU/Linux below script works well #!/bin/bash eval ssh remotehost date eval ssh remotehost ls below... (1 Reply)
Discussion started by: summer_cherry
1 Replies

9. Shell Programming and Scripting

Replacement for eval in Perl??????

I used the eval command in shell programming for assigning a value to a stored value of a variable. Example: VAR="Unix_Id" eval $VAR="101" eval echo $"$VAR" How can i assign a value to a stored value of a variable in perl OR how i can write above code in Perl? I need your help... (4 Replies)
Discussion started by: kunal_dixit
4 Replies

10. Shell Programming and Scripting

perl: eval and constants

is it possible to use eval to create constants in perl? i cannot seem to get anything to work, and my searches are turning up little to nothing. an example of what i am trying to do is this: 2 arrays: array 1: 'FOOD','NUMBER','OS' array 2: 'pizza','two','unix' loop through the arrays and... (5 Replies)
Discussion started by: effigy
5 Replies
Login or Register to Ask a Question