Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: using symbol table lookup

by dragonchild (Archbishop)
on Sep 25, 2001 at 20:04 UTC ( #114565=note: print w/replies, xml ) Need Help??


in reply to using symbol table lookup

What on earth do you want to fiddle with the symbol table for?? It's dangerous, messy, and there's better ways to do it.

As for your questions, *variables is bound to *main:: when you bind it. Hence, if the variable hasn't been created yet, it's not in *main::. Compilation doesn't populate anything. All it does is convert the script to opcodes. When those opcodes execute, that's when the SV's are created, and a reference entered into *main::.

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Replies are listed 'Best First'.
Re: Re: using symbol table lookup
by asinghvi (Acolyte) on Sep 25, 2001 at 20:18 UTC
    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.)
    .
      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).

      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://114565]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (None)
    As of 2021-10-17 03:53 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My first memorable Perl project was:







      Results (71 votes). Check out past polls.

      Notices?