Re: Perl include question

2005-12-07 Thread Paul Lussier
Dan Coutu <[EMAIL PROTECTED]> writes:

> Piece of cake. You need to use the FindBin module that is included in
> the default Perl distribution. Do this:
>
> #!/usr/bin/perl
> use FindBin qw($Bin);
> use lib "$Bin";
> use myinclude;
>
> This assumes that your module is named myinclude.pm and is in the same
> directory as your perl script.

I was just about to make this same recommendation.  We've got hundreds
of thousands of lines of perl code here at work, and this is where I
first discovered the FindBin module.  We use it extensively here, and
probably wouldn't be able to do things nearly as easily without it.

Almost every script we write has:

   use FindBin;
   use lib "/build/perl/lastrun/lib";
   use lib "$FindBin::Bin/../../../perl/lib";
   use lib $FindBin::Bin;

It's really nice to not have to worry about your modules not being found :)

-- 

Seeya,
Paul
___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss


Re: Perl include question

2005-12-05 Thread Jeff Macdonald
On 12/5/05, Dan Coutu <[EMAIL PROTECTED]> wrote:
> use FindBin qw($Bin);
> use lib "$Bin";
> use myinclude;

all of my perl code does basically this, but I stick things in a lib directory:

/some/directory/myapp
/some/directory/myapp/lib

so the use lib line above would turn into

use lib "$Bin/lib";

makes things a little easier to manage.

--
Jeff Macdonald
Ayer, MA
___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss


Re: Perl include question

2005-12-05 Thread Thomas Charron
On 12/5/05, Cole Tuininga <[EMAIL PROTECTED]> wrote:
On Mon, 2005-12-05 at 15:59 -0500, Thomas Charron wrote:> use lib '.';Doesn't this assume you're executing the script from its own directory?
In other words, wouldn't this break if I did something like:../otherpath/script.pl
 
  Yeppers..  ;-)  It was a quick reply, didn't have time to fully explain it.  But it's all in the use lib line.  ;-)
 
  Thomas 


Re: Perl include question

2005-12-05 Thread Kevin D. Clark

Cole Tuininga writes:

> I have a module (call it MyMod.pm) that I want to use in a program, but
> I can't install it in with the rest of the perl libraries.  For reasons
> that are too boring to get into, the only guarantee I have is that it
> will be in the same directory as the executable script.
>
> How can I set up my include path (within the perl script) to make sure
> that the directory of the executable is in the include path?  I can't
> hard code it because the location might be different on different
> machines (different mount points).


Try this:

  #!/usr/bin/perl

  BEGIN {
$dirname = $0;
$dirname =~ s#(.*/).*#$1#;
eval "use lib qw($dirname)";
  }

  use MyMod;


Hope this helps,

--kevin
-- 
GnuPG ID: B280F24E

___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss


Re: Perl include question

2005-12-05 Thread Dan Coutu
On Mon, 2005-12-05 at 15:59 -0500, Thomas Charron wrote:
> use lib '.';
>  
>   Thomas
> 
Note that this will use your current directory as the place it looks for
your module. The current directory would happen to depend on wherever
you happen to have last done a cd to. That may not be what you really
want. Chances you really want the module to be in the same directory as
the perl script itself, or a directory relative to it. For that FindBin
is the way to go.

Dan


> On 12/5/05, Cole Tuininga <[EMAIL PROTECTED]> wrote: 
> How can I set up my include path (within the perl script) to
> make sure
> that the directory of the executable is in the include
> path?  I can't 
> hard code it because the location might be different on
> different
> machines (different mount points).

___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss


Re: Perl include question

2005-12-05 Thread Cole Tuininga
On Mon, 2005-12-05 at 15:59 -0500, Thomas Charron wrote:
> use lib '.';

Doesn't this assume you're executing the script from its own directory?
In other words, wouldn't this break if I did something like:

../otherpath/script.pl


-- 
"The best firewall is a pair of wire cutters."
-Unknown, from the net

Cole Tuininga
Lead Developer
Code Energy, Inc
[EMAIL PROTECTED]
PGP Key ID: 0x43E5755D


___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss


Re: Perl include question

2005-12-05 Thread Dan Coutu
On Mon, 2005-12-05 at 15:25 -0500, Cole Tuininga wrote:
> How can I set up my include path (within the perl script) to make sure
> that the directory of the executable is in the include path?  I can't
> hard code it because the location might be different on different
> machines (different mount points).
> 
Piece of cake. You need to use the FindBin module that is included in
the default Perl distribution. Do this:

#!/usr/bin/perl
use FindBin qw($Bin);
use lib "$Bin";
use myinclude;

This assumes that your module is named myinclude.pm and is in the same
directory as your perl script.

For more details use "perldoc FindBin" on the command line.

Dan

___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss


Re: Perl include question

2005-12-05 Thread Thomas Charron
use lib '.'; 
  Thomas
 
On 12/5/05, Cole Tuininga <[EMAIL PROTECTED]> wrote:
How can I set up my include path (within the perl script) to make surethat the directory of the executable is in the include path?  I can't
hard code it because the location might be different on differentmachines (different mount points).