in reply to RE: getting hashes out of config files
in thread getting hashes out of config files

that works nicely, except for one problem:

do('$filename');

doesn't seem to work, however if i type the path and file instead of using $filename variable it works ... is there a way to use the $filename variable with the do function?

it tend to be much more usefull to use a variable ... its a lot sorter thanks in advance
  • Comment on RE: RE: getting hashes out of config files

Replies are listed 'Best First'.
RE: RE: RE: getting hashes out of config files
by Fastolfe (Vicar) on Oct 25, 2000 at 22:34 UTC
    You're using single quotes, which do not do variable interpolation. Thus, you are attempting to open the file named $filename (literally). Remove the quotes entirely, as they're unnecessary, or use double-quotes, which will correctly do interpolation:
    do($filename) or die "..."; do("$filename") or die "...";
      double quotes and no quotes yield the same result as single quotes ... i have been using hte following to test:
      do('filename'); %hashname = %$VAR1; print "$hashname{name} \n\n"; ###the above works fine ###the code below only prints the \n's $filename = "filename"; do($filename); %hashname = %$VAR1; print "$hashname{name} \n\n";
      thanks again
        This works for me:
        $ cat test do('test2'); print "var=$var\n"; $ cat test2 $var="test variable"; $ perl test var=test variable
        Make sure 'filename' exists and is valid Perl. In addition, each of my examples has included an 'or die...' bit, yet you've consistently ignored this hint. Upon failure, do will return undef and set either $! to an error indicating a failure to read the file, or $@ with an error message describing a compilation or run-time error evaluating the contents of the file. Check for these errors and print them out. I suspect your problem will be clear at that point.
        do($filename) or die "$filename: " . ($! ? $! : $@);