Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Re: using symbol table lookup

by asinghvi (Acolyte)
on Sep 25, 2001 at 20:18 UTC ( #114570=note: print w/replies, xml ) Need Help??


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....

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://114570]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2021-09-20 18:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?