Author:
erics , April 16th, 2021
The key is to define a variable first, then use the BEGIN block to initialize the variable, then reference the variable in use lib $var; later on ;-} For example, enable a module contained in the same directory as a script called via the PATH:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/ussr/bin/env perl
use strict ;
use warnings ;
our $ scriptPath ;
BEGIN {
eval {
use File :: Basename ;
use File :: Spec ;
$ scriptPath = dirname ( File :: Spec -> rel2abs ( __FILE__ ) ) ;
1 ;
} or do {
die "$0 use CRASHED: $@" ;
} ;
}
use lib $ scriptPath ;
eval {
use MyModule :: ABC ;
1 ;
} or do {
die "$0 use CRASHED: $@" ;
} ;
Categories: How-To's , Technology Tags: @INC , compile , Compile-time , Dir , directory , howto , include , lib , Library , module , Path , perl , require , Run-time , runtime , tips , Use , use lib
| No comments
Author:
erics , April 12th, 2012
For example, to see the version for DBD::mysql, do this: perl -MDBD::mysql -we ‘print $DBD::mysql::VERSION;’
Categories: How-To's , Technology Tags: DBD , DBD::mysql , howto , module , mysql , perl , tips , Version
| No comments
Author:
erics , December 15th, 2011
Below information copied without permission from Josh Sharp’s site because it is too valuable to lose – great work Josh, and THANKS!
RewriteEngine On
RewriteCond % { REQUEST_FILENAME } ! - d
RewriteCond % { REQUEST_FILENAME } ! - f
RewriteRule ^ ( . * ) $ index . php ? url = $ 1 [ QSA , L ]
Note: Only rewrite if the requested file is not an existing directory (-d) or a file (-f)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
include ( 'app/classes.php' ) ;
include ( 'app/app.php' ) ;
//init our app
$ App = new App ;
//grab the mod_rewrite url
$ url = $ _REQUEST [ 'url' ] ;
//if the url is empty then the user has navigated just to root
if ( $ url == '' ) {
//start with default controller
$ App -> setController ( 'home' ) ;
} else {
//grab each part of our URL - controller, action, and identifier
$ path = explode ( '/' , $ url , 3 ) ;
//pass these onto the app to handle
$ App -> setController ( $ path [ 0 ] , $ path [ 1 ] , $ path [ 2 ] ) ;
}
Categories: How-To's , Technology Tags: apache , mod_rewrite , module , Path , php , Rewrite , SEO , URL
| No comments
Author:
erics , September 29th, 2009
[code lang=”perl”] #!/bin/perl use ExtUtils::Installed; my $instmod = ExtUtils::Installed->new(); foreach my $module ($instmod->modules()) { my $version = $instmod->version($module) || "???"; print "$module — $version\n"; } [/code]
Categories: How-To's , Technology Tags: howto , installed , module , perl , tips
| No comments