Hi,
 
The simple way to resolve your problem is to add a '1' at the end of 
"/opt/user.rules".
But you must know,that logic pieces in the "/opt/user.rules" CAN'T work at all 
for your main.pl.
You can define a package variable or a subroutine in the required file,then the 
main script can use that package variable and the subroutine.For example,in the 
"/opt/user.rules",you can write:
 
our $foo = 'abcd';
sub bar {
    #some logic statement here
}
 
1;
 
Then in the main.pl you can write them like:
 
require "/opt/user.rules";
our $foo;
print $foo; #get 'abcd'
bar(); #get the subroutine defined in the 'user.rules' to be executed
 
__END__
 
Hope this helps.
 
--Jeff Pang
 
 
 
-----Original Message-----
From: [EMAIL PROTECTED]
To: beginners@perl.org
Sent: Sat, 16 Sep 2006 9:33 PM
Subject: Including code from a file into the main script if the file exists


Hi: I have a script called main.pl. I want to include
few lines of code from another file called user.rules
if it exists. I have tried using the require statement
to do that as shown below within the main.pl. 

if (-e "/opt/user.rules")
{
   require "/opt/user.rules";
}

I get the following error
/opt/user.rules did not return a true value at (eval
3) line 627.


within the user.rules file I have some perl statements
like
=================
if($token6 =~ /Guard5650/) {
   handleGuard5650($whole_event_string);
   $dropEvent = 0;
} elsif($token6 =~ /Detector5600/ or $token5 eq "cm:")
{
   handleDetector5600($whole_event_string);
   $dropEvent = 0;
}
===================

Is there a different way to do this?

Thanks
Ravi

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
________________________________________________________________________
Check out the new AOL.  Most comprehensive set of free safety and security 
tools, free access to millions of high-quality videos from across the web, free 
AOL Mail and more.

Reply via email to