in reply to Re: using symbol table lookup
in thread using symbol table lookup

My purpose is that my perl scripts read many text files
So rather than checking each one in each script, I thought
I would always make my filename variables always as
"something_file". And have a standard subroutine that checks
all %main:: scalar variables  =~ /\_file/ and do the checks
on each entry (Like file exists, file is readable etc.)

Replies are listed 'Best First'.
Re: Re: Re: using symbol table lookup
by chromatic (Archbishop) on Sep 25, 2001 at 20:26 UTC
    Use Exporter, or write a subroutine in each program that returns the filename, or a hash reference of values.

    Leave symbol-table mucking about for when there's really no other way to do that (basically run-time code generation).

Re: Re: Re: using symbol table lookup
by tachyon (Chancellor) on Sep 25, 2001 at 20:29 UTC

    Rather odd way to do it I would have thought. Is there something inherently wrong with this approach:

    my $dir = 'c:/'; opendir DIR, $dir or die "Oops cna't open $dir $!\n"; my @files = grep { /\.pl$/ } readdir DIR; close DIR; $_ = $dir.$_ for @files; # add full path print "Here are all the files:\n"; print "$_\n" for @files;

    This finds all the files in my root dir which end in .pl but I could use the regex in the grep to match anything. I don't see any reason to mess with the symbol table. Just wrap this sort of code in a sub that you can call from wherever....