The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Getting warning in the Perl Script pulkit Shell Programming and Scripting 4 02-08-2008 05:21 AM
[ID 882636 kern.warning] WARNING: interrupt level 11 not serviced voxure SUN Solaris 9 01-30-2006 01:49 AM
using eval with set, wc, and expr wxornot Shell Programming and Scripting 2 01-08-2006 12:42 PM
use of eval n grep abhi UNIX for Dummies Questions & Answers 3 02-17-2005 06:38 AM
perl: eval and constants effigy Shell Programming and Scripting 5 01-23-2005 03:24 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-25-2008
sameerstephen's Avatar
Registered User
 

Join Date: Sep 2007
Posts: 4
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 02:48 AM. Reason: added code tags
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-25-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,094
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.
Reply With Quote
  #3 (permalink)  
Old 03-26-2008
sameerstephen's Avatar
Registered User
 

Join Date: Sep 2007
Posts: 4
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.
Reply With Quote
  #4 (permalink)  
Old 03-26-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,094
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.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:03 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0