Ask a Question related to PERL Beginners, Design and Development.
-
Robin Sheat #1
Including files to pick up variables
Hey there, what is the best way of including a Perl so that the contents
of it override the existing variables. For example, I have:
<main Perl program>
...
my $comment = "Default\n";
my $resDir = "results";
...
if (@ARGV) {
my $c = shift;
$config = "testing/$c.pm";
unless (my $ret = do $config) {
die "couldn't parse $config: $@" if $@;
die "couldn't do $config: $!" unless defined $ret;
die "couldn't run $config" unless $ret;
}
# Get the output filehandle
$output = getOutputFH();
}
...
<a file in testing/>
$comment = "A not quite default test.";
my $resName = 'notdefault.res';
sub getOutputFH() {
open($fh, ">${resDir}/${resName}.res") or ***
die "Can't open results file: $!";
return $fh;
}
1;
I would like the value of $comment defined in the testing file to
override the value defined in the main program. I would also
like for the value of $resDir to be picked up by the getOutputFH() sub,
however neither of these happens. What is the best way of doing what I'm
trying to acheive here?
(Obviously, in real life, more things are going to be set, but if I can
make this example work, it is a short step to getting the rest working)
The error I get is "Use of uninitialized value in concatenation (.) or
string" at the point marked '***'. I assume it is $resDir not being
defined.
I know that I could simply have a function that returns a hash (list)
that I walk through to set the variables, but I want to keep this as
simple as possible, as I'll be creating lots of little versions of these
testing files, and the more stuff in them, the more there is to go
wrong.
--
Robin <robin@kallisti.net.nz> JabberID: <eythian@jabber.org>
Hostes alienigeni me abduxerunt. Qui annus est?
PGP Key 0x776DB663 Fingerprint=DD10 5C62 1E29 A385 9866 0853 CD38 E07A 776D B663
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFALEQMzTjgendttmMRApu0AJ9jo66KTGO+GTTaF25u64 FLKpk6uQCfbdGe
K0JRuNJlTXtDmEo1mgwHRew=
=4YF+
-----END PGP SIGNATURE-----
Robin Sheat Guest
-
Including files with a control
I am attempting to make an ASP.NET server control (inheriting from System.Web.UI.Control) and, when the control is dragged from the Visual Studio... -
Including text files in Modules
Greetings, Q1. Is it possible to include txt files (as data sources) inside a Perl package? (not to dump the contents as some kind of variables;... -
including files in other directories
I have some code running on windows on my local machine that uses the jpgraph image library. I include the jpgraph libs using include... -
strategies for including files when you're not allowed to make assumptions about directory names
2 Questions: 1.) Can anyone think of a way to speed up this function? It is terribly slow. I plan to reduce the number of directories to 3, which... -
including html files in a .html page
4bb: Investigate Server-side includes. If your host supports them, they do just what you want. Be aware that the file included MUST BE AN... -
Robin Sheat #2
Re: Including files to pick up variables
On Fri, Feb 13, 2004 at 04:27:08PM +1300, Robin Sheat wrote:
With all the help of those who replied ;) I worked it out. For the> Hey there, what is the best way of including a Perl so that the contents
> of it override the existing variables. For example, I have:
benefit of others:
needs to be:> my $comment = "Default\n";
our $comment = "Default\n";
Then everything just works.
--
Robin <robin@kallisti.net.nz> JabberID: <eythian@jabber.org>
Hostes alienigeni me abduxerunt. Qui annus est?
PGP Key 0x776DB663 Fingerprint=DD10 5C62 1E29 A385 9866 0853 CD38 E07A 776D B663
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFALZBzzTjgendttmMRAn/NAKC7Vwy3gRrIfMlBSB1eJ9PsC1h7wwCfWXxE
WsITUrLFnHXkOYCUvV/TPgI=
=F5+A
-----END PGP SIGNATURE-----
Robin Sheat Guest



Reply With Quote

