read vars from external file and execute them.

tgh73
tgh73 used Ask the Experts™
on
How to read a variable from an external file and execute them, but without require directive?
The finished program should run as a Win32 executable
program without Perl environment, so I have to compile
it by perl2exe, so require directive will not work.
example:
- a file named config.cfg which contains:
  $start=strftime "%H:%M:%S", localtime;

What code should I have in program.pl to get a real hour,
12:30:41 for example?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
#!/usr/bin/perl
use POSIX qw(strftime);
open(FILE,"config.cfg") || die("Could not open file because $!");
$/ ='';
$code=<FILE>;
close(FILE);
eval($code);
print $start;

Author

Commented:
Works fine, thank You.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial