Re: perl


Subject: Re: perl
From: Arthur Corliss (arthur@corlissfamily.org)
Date: Sun Apr 14 2002 - 22:25:49 AKDT


> Thanks, I'll try that out tonight. From what I was reading it
> sounds like I can just issue the command "use file_name" inside a
> script, and as long as that script is in the same directory it
> should work? I'm still trying to figure out how to deal with the
> @INC list. Does this @INC actually exist in a file somewhere?
>
> Thanks Arthur for your suggestions too. I wish I was at the point
> where managing the name space was something I was thinking about.
> I'm just a couple of pages past the "Hello world" tutorial ;), but
> then again I guess it is better to start learning good form rather
> than bad, eh?

If you want to add a directory to your search path (@INC), just use the
following:

    use lib qw(/usr/lib/foo /usr/lib/bar);

which adds the two specified directories. As to the 'use' or 'require'
syntax, I'd recommend doing the following:

    $module = "MyModule";
    $tmp->import if eval "require $tmp";

This will search your @INC for the specified module (*.pm), load it, and
import any default symbols. For what you're doing, though, it sounds like
you just want to import a standard *.pl file, to which I'd recommend you just
eval the require call on that file:

    unless (eval "require foo.pl") {
        die "Couldn't load foo.pl!\n";
    }

This will let you safely control what happens should the file not be
available, etc.

--

--Arthur Corliss Bolverk's Lair -- http://arthur.corlissfamily.org/ Digital Mages -- http://www.digitalmages.com/ "Live Free or Die, the Only Way to Live" -- NH State Motto

--------- To unsubscribe, send email to <aklug-request@aklug.org> with 'unsubscribe' in the message body.



This archive was generated by hypermail 2a23 : Mon Apr 15 2002 - 16:21:26 AKDT