[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Omaha.pm] weee, I get to use perl again
My $0.02, FWIW --
On Aug 24, 2007, at 6:36 PM, Jesse Andersen wrote:
I could be wrong, but wouldn't something like the following work
for what you want to do? the path will stay relative to your script.
#!/usr/bin/perl -w
open(IN, "<../test/test.txt");
That should work fine if you're manually running the Perl program
from the current directory. But does it work if you provide a full
path? Will it work in a cron job?
On Aug 24, 2007, at 10:26 PM, Christopher Cashell wrote:
use FindBin qw($Bin);
use lib "$Bin";
use vars qw($user $pass $url $ids_ver $max_events);
require "ids_check.conf";
FindBin is cool. Hadn't seen that one in a while.
So ids_check.conf basically looks like this?
$user = 'wally';
"perldoc vars" says that 'vars' is deprecated, and you should use
'our' instead? (perldoc -f our) I don't use either, though, so what
do I know? :)
------------
Thought # 1
------------
Don't know if "our way" is good or bad, but we decreed that all our
in-house perl will always live in one absolute path:
/usr/lib/perl5/site_perl/Omni
And our MVC class structure begins in the absolute path
/usr/lib/perl5/site_perl/Omni/MVC
So when an admin installs a new Linux box, they
cd /usr/lib/perl5/site_perl
cvs checkout -d Omni source/common/perl
export PERL5LIB=/usr/lib/perl5/site_perl/Omni/MVC
and they're done. Cron jobs and hard-coded to absolute paths, that
are in turn hard-coded with absolute paths of their own if they need
to read files.
Consequence: You can't choose to install our 172K lines of Perl
somewhere else, even if you wanted to. Parts of it won't work. (Looks
like we have 287 unit test scripts running 17,493 subtests nowadays...)
-ponder- It's not a problem for us, since it's always root
installing the bundle into the exact same path. (Makes admin job
easy. -grin-)
------------
Thought # 2
------------
On occasion when I have wanted people to be able to install my source
code wherever they choose I have used an environment variable.
my $file = "$ENV{OTA2_PATH}/skeletons/$filename.xml";
$twig->parsefile($file) or die "Can't load '$file'";
Tests are skipped like so
use Test::More;
if( -d "$ENV{OTA2_PATH}/skeletons" ) {
plan tests => 4;
} else {
plan skip_all => 'Looks like your $ENV{OTA2_PATH} is not set';
}
If they don't have the right environment variable set they just get
an error.
$ perl Errors.t
1..0 # Skip Looks like your $ENV{OTA2_PATH} is not set
HTH,
j