Re: 'Use Lib' problem...

2005-08-01 Thread Tony Frasketi

Sorry... Didn't notice that's what it was
Tony

Dave Gray wrote:


On 7/26/05, Tony Frasketi <[EMAIL PROTECTED]> wrote:
 


I'm trying to use the following 'use lib' statement as described at
http://www.unix.org.ua/orelly/perl/prog3/ch31_13.htm
   



It's not nice to link to pirated copies of books. BAD.

 



Re: 'Use Lib' problem...

2005-08-01 Thread Dave Gray
On 7/26/05, Tony Frasketi <[EMAIL PROTECTED]> wrote:
> I'm trying to use the following 'use lib' statement as described at
>  http://www.unix.org.ua/orelly/perl/prog3/ch31_13.htm

It's not nice to link to pirated copies of books. BAD.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: 'Use Lib' problem...

2005-08-01 Thread Jeff 'japhy' Pinyan

On Jul 30, Tony Frasketi said:


 CGIDIR=$HOME/cgi-bin
 PMDIR=$CGIDIR/pm
 export CGIDIR PMDIR

Then in my CGI script I have...
 -
 use lib "$PMDIR";


No, you need to use $ENV{PMDIR} here.  Environment variables are stored in 
the %ENV hash.


--
Jeff "japhy" Pinyan %  How can we ever be the sold short or
RPI Acacia Brother #734 %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %-- Meister Eckhart

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: 'Use Lib' problem...

2005-07-31 Thread Tony Frasketi
Sorry... I've since discovered that my approach in fact DID NOT solve my 
problem I inadvertently place my perl module in the SAME directory 
as my CGI file and of course that would always work. So it looks like 
I'm back to square one. Still looking for a zimple solution to avoid 
explicitly naming the path to the directory where my perl modules reside


I still DO NOT understand why the shell variable definition method 
(.bash_profile and .bashrc) DID NOT work Anyone?


Perhaps I'd also better investigate the 'export PERL5LIB' method that 
Tom suggested.

Thanks
Tony Frasketi


Hello Tom
I've been successful in getting my use lib statment to work by inserting 
the following statments in my .bash_profile file as follows


 CGIDIR=$HOME/cgi-bin
 PMDIR=$CGIDIR/pm
 export CGIDIR PMDIR

Then in my CGI script I have...
 -
 use lib "$PMDIR";
 use WSP qw(%WSP); # My web site parameter definitions

 print "Content-type: text/html\n\n";
 foreach $name (sort keys(%WSP)) {
 print "$name = $WSP{$name}\n";
  }
 -
Where WSP is where I've define my web site parameters. I then print out 
those parameters and it all works.


However there is something that I don't understand Since I've 
defined CGIDIR and PMDIR shell variables in .bash_profile and exported 
them, they are available to be used in my CGI applications according to 
what I've read. And this is certainly true because my 'use lib "$PMDIR" 
' statement has successfully utilized the PMDIR definition.  What I 
don't understand then is why  when I use the following print statements, 
I don't get the expected values. I get nothing


 print  "CGIDIR [$CGIDIR]";
 print  "PMDIR [$PMDIR]";

Can you shed some light on this for me?
Thanks
Tony

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: 'Use Lib' problem...

2005-07-30 Thread Tony Frasketi

Hello Tom
I've been successful in getting my use lib statment to work by inserting 
the following statments in my .bash_profile file as follows


  CGIDIR=$HOME/cgi-bin
  PMDIR=$CGIDIR/pm
  export CGIDIR PMDIR

Then in my CGI script I have...
  -
  use lib "$PMDIR";
  use WSP qw(%WSP); # My web site parameter definitions

  print "Content-type: text/html\n\n";
  foreach $name (sort keys(%WSP)) {
  print "$name = $WSP{$name}\n";
   }
  -
Where WSP is where I've define my web site parameters. I then print out 
those parameters and it all works.


However there is something that I don't understand Since I've 
defined CGIDIR and PMDIR shell variables in .bash_profile and exported 
them, they are available to be used in my CGI applications according to 
what I've read. And this is certainly true because my 'use lib "$PMDIR" 
' statement has successfully utilized the PMDIR definition.  What I 
don't understand then is why  when I use the following print statements, 
I don't get the expected values. I get nothing


  print  "CGIDIR [$CGIDIR]";
  print  "PMDIR [$PMDIR]";

Can you shed some light on this for me?
Thanks
Tony

Tony Frasketi wrote:


Hey Tom
Thanks for the response.
That's what I was afraid of and wanted to avoid - Having this in all 
my scripts. I think I'll look into the '~/.bashrc, ~/bash_profile, 
/etc/profile' route. If I can get that to work, then I'll have what I 
want.

Thanks for the help!
Tony Frasketi

Tom Allison wrote:


Tony Frasketi wrote:

Thanks Tom for the quick response... But could you please elaborate 
a bit on what these two lines do?


  export PERL5LIB=$PERL5LIB:$HOME/lib
  myperlscript.pl

and where would I use them, in a single script? in all my scripts?
Thanks
Tony



Unfortunately it would be in all your scripts.
Unless...

you can either add something like this to you ~/.bashrc, 
~/bash_profile, /etc/profile (depending on how you want to use it).


I have a similar issue with a Solaris box at work and can't get the 
right permissions to configure the files I need.  So I have to wrap 
everything in a script and include that "export PERL5LIB" string in 
every single file that I run from crontab.


It's not as bad as it sounds.  It's really better to run crontab jobs 
from wrapper scripts but sometimes I'm just lazy about it.








--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: 'Use Lib' problem...

2005-07-26 Thread Jeff 'japhy' Pinyan

On Jul 26, Tony Frasketi said:


   $ENV{HOME} = 'home/tony/cgi-bin'; # My cgi-bin directory


Are you sure there shouldn't be a / at the beginning of that?


   use lib "$ENV{HOME}/pm";  # Add my personal perl module directory


The problem is that 'use lib' happens at compile-time, but your assignment 
to $ENV{HOME} doesn't happen until run-time.  A simple fix in your case 
is:


  BEGIN {
$ENV{HOME} = "/home/tony/cgi-bin";
  }
  use lib "$ENV{HOME}/pm";

The BEGIN { } block forces its contents to be executed at compile-time.

--
Jeff "japhy" Pinyan %  How can we ever be the sold short or
RPI Acacia Brother #734 %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %-- Meister Eckhart

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: 'Use Lib' problem...

2005-07-26 Thread Tom Allison

Tony Frasketi wrote:

Hello listers

I'm trying to use the following 'use lib' statement as described at
http://www.unix.org.ua/orelly/perl/prog3/ch31_13.htm

use lib "$ENV{HOME}/libperl"; # add ~/libperl

In a *test* program, I've written

$ENV{HOME} = 'home/tony/cgi-bin'; # My cgi-bin directory
use lib "$ENV{HOME}/pm";  # Add my personal perl module 
directory (pm)


However this method doesn't seem to work for me... printing out @INC 
gives me...
0 /pm   <---Incorrect/incomplete  
location of my personal perl module directory

1 /usr/lib/perl5/5.6.1/i386-linux
2 /usr/lib/perl5/5.6.1
3 /usr/lib/perl5/site_perl/5.6.1/i386-linux
4 /usr/lib/perl5/site_perl/5.6.1
5 /usr/lib/perl5/site_perl/5.6.0
6 /usr/lib/perl5/site_perl
7 /usr/lib/perl5/vendor_perl/5.6.1/i386-linux
8 /usr/lib/perl5/vendor_perl/5.6.1
9 /usr/lib/perl5/vendor_perl
10 .


However if I use the following...

use lib "home/tony/cgi-bin/pm";

This works! printing out @INC give me
0 /home/tonysf/cgi-bin/pm   <--- Correct 
Location of my personal perl module directory (pm)

1 /usr/lib/perl5/5.6.1/i386-linux
2 /usr/lib/perl5/5.6.1
3 /usr/lib/perl5/site_perl/5.6.1/i386-linux
4 /usr/lib/perl5/site_perl/5.6.1
5 /usr/lib/perl5/site_perl/5.6.0
6 /usr/lib/perl5/site_perl
7 /usr/lib/perl5/vendor_perl/5.6.1/i386-linux
8 /usr/lib/perl5/vendor_perl/5.6.1
9 /usr/lib/perl5/vendor_perl
10 .


What I'm trying to avoid is having all my scripts platform dependent by 
hard coding my personal perl module directory in the 'use lib' 
statement. I'd like to set the actual $ENV{HOME}environment variable in 
my home script to the location of my cgi-bin directory and have it 
applied automatically to all my scripts simply by referencing $ENV{HOME}..


Hoping I've explained this properlu
Thanks in advance.
tony




I didn't think you could interpret the variable $HOME or $ENV{HOME} in 
single quotes.


'$ENV{HOME}' is literally what you see.
"$ENV{HOME}" would get you /home/username/

But under use libs, it seems that they are all interpreted...

The only suggestion this noob has is to wrap it up into a shell script:

export PERL5LIB=$PERL5LIB:$HOME/lib
myperlscript.pl



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




'Use Lib' problem...

2005-07-26 Thread Tony Frasketi

Hello listers

I'm trying to use the following 'use lib' statement as described at
http://www.unix.org.ua/orelly/perl/prog3/ch31_13.htm

use lib "$ENV{HOME}/libperl"; # add ~/libperl

In a *test* program, I've written

$ENV{HOME} = 'home/tony/cgi-bin'; # My cgi-bin directory
use lib "$ENV{HOME}/pm";  # Add my personal perl module 
directory (pm)


However this method doesn't seem to work for me... printing out @INC 
gives me...
0 /pm   <---Incorrect/incomplete  
location of my personal perl module directory

1 /usr/lib/perl5/5.6.1/i386-linux
2 /usr/lib/perl5/5.6.1
3 /usr/lib/perl5/site_perl/5.6.1/i386-linux
4 /usr/lib/perl5/site_perl/5.6.1
5 /usr/lib/perl5/site_perl/5.6.0
6 /usr/lib/perl5/site_perl
7 /usr/lib/perl5/vendor_perl/5.6.1/i386-linux
8 /usr/lib/perl5/vendor_perl/5.6.1
9 /usr/lib/perl5/vendor_perl
10 .


However if I use the following...

use lib "home/tony/cgi-bin/pm";

This works! printing out @INC give me
0 /home/tonysf/cgi-bin/pm   <--- Correct 
Location of my personal perl module directory (pm)

1 /usr/lib/perl5/5.6.1/i386-linux
2 /usr/lib/perl5/5.6.1
3 /usr/lib/perl5/site_perl/5.6.1/i386-linux
4 /usr/lib/perl5/site_perl/5.6.1
5 /usr/lib/perl5/site_perl/5.6.0
6 /usr/lib/perl5/site_perl
7 /usr/lib/perl5/vendor_perl/5.6.1/i386-linux
8 /usr/lib/perl5/vendor_perl/5.6.1
9 /usr/lib/perl5/vendor_perl
10 .


What I'm trying to avoid is having all my scripts platform dependent by 
hard coding my personal perl module directory in the 'use lib' 
statement. I'd like to set the actual $ENV{HOME}environment variable in 
my home script to the location of my cgi-bin directory and have it 
applied automatically to all my scripts simply by referencing $ENV{HOME}..


Hoping I've explained this properlu
Thanks in advance.
tony


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




[ot: "test"] Re: use lib problem

2003-08-02 Thread Randal L. Schwartz
> "Jeff" == Jeff 'Japhy' Pinyan <[EMAIL PROTECTED]> writes:

Jeff> On Aug 2, awarsd said:
>> #!/usr/bin/perl
>> 
>> use CGI qw(:standard);
>> use DBI;
>> 
>> require "/path/to/config.pl";
>> ##inside config.pl it has $dataDir
>> ##$dataDir = "/path/to/";
>> use lib $dataDir."Module";
>> use Test;

Jeff> You named your module "Test"?  That's why you're getting a false positive.
Jeff> There's a standard module named Test; it's being use'd, instead of your
Jeff> module.

This may be the first occurance "in the wild" of the "test" overload,
comparable to naming your Perl program "test" and then wondering
why it doesn't generate any output when invoked as

$ test

because that's actually executing the shell built-in called "test".
You have to use

$ ./test

to get the program to run.  Hence, in the Llama, we advocate always
starting a proggram with "./" if it's in the current directory.

print "Just another Perl [book] hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: use lib problem

2003-08-02 Thread Jeff 'japhy' Pinyan
On Aug 2, awarsd said:

>#!/usr/bin/perl
>
>use CGI qw(:standard);
>use DBI;
>
>require "/path/to/config.pl";
> ##inside config.pl it has $dataDir
>##$dataDir = "/path/to/";
>use lib $dataDir."Module";
>use Test;

You named your module "Test"?  That's why you're getting a false positive.
There's a standard module named Test; it's being use'd, instead of your
module.

The 'use lib ...' statement happens at COMPILE-time.  The 'require ...'
statement happens at RUN-time.  COMPILE-time is before RUN-time, so 'use
lib ...' happens first, and $datadir is EMPTY then, because it hasn't been
filled, because 'require ...' hasn't happened yet.

You must do two things:

1. rename your module, to something like MyStuff.pm
2. put the 'require ...' code inside a BEGIN block

  BEGIN { require "/path/to/config.pl" }
  use lib "$dataDir/Module";
  use MyStuff;

>Should I declare variable i.e
>my $datDir inside the program or in the config.pl??
>Also should i declare in module $main::dataDir like
>my $main::dataDir; or I can just leave $main::dataDir??

If you declare any my() variables in config.pl, NO OTHER FILE can see
them.  Therefore, do NOT make $dataDir a my() variable.  Furthermore, a
my() variable CANNOT belong to a package, so you can't say my $main::var.
It just doesn't make sense.

Leave your variables as they are.

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: use lib problem

2003-08-02 Thread awarsd
Hi,

here is the actual top of the file


#!/usr/bin/perl

use CGI qw(:standard);
use DBI;

require "/path/to/config.pl";
 ##inside config.pl it has $dataDir
##$dataDir = "/path/to/";
use lib $dataDir."Module";
use Test;
...

Should I declare variable i.e
my $datDir inside the program or in the config.pl??
Also should i declare in module $main::dataDir like
my $main::dataDir; or I can just leave $main::dataDir??

Anthony



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: use lib problem

2003-08-02 Thread Jeff 'japhy' Pinyan
On Aug 2, awarsd said:

>no sorry it is not use but use lib $datadir."Module";

That doesn't change the fact that $datadir does NOT have a value when the
'use' line happens.  Is the require() being done in a BEGIN block?  If so,
you neglected to show us that as well.

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: use lib problem

2003-08-02 Thread awarsd
Hi,

no sorry it is not use but use lib $datadir."Module";
just a typo

awards

"Jeff 'Japhy' Pinyan" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On Aug 2, awarsd said:
>
> >I messed around and found that
> >if in config i do $datadir = "/my/path/";
> >instead o f$datadir= "/my/path";
> >
> >then in my script i do
> >#!/usr/bin/perl
> >require 'config.pl';
> >use $datadir."Module";
> >
> >everything works again.
>
> I don't know how "everything works".  You haven't changed the problem at
> all.  That gives me a syntax error.  And even if it didn't, you haven't
> changed the fact that 'use' is using $datadir, which HAS NOT BEEN DEFINED
> yet.
>
> -- 
> Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
> RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
>  what does y/// stand for?   why, yansliterate of course.
> [  I'm looking for programming work.  If you like my work, let me know.  ]
>
>



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: use lib problem

2003-08-02 Thread Jeff 'japhy' Pinyan
On Aug 2, awarsd said:

>I messed around and found that
>if in config i do $datadir = "/my/path/";
>instead o f$datadir= "/my/path";
>
>then in my script i do
>#!/usr/bin/perl
>require 'config.pl';
>use $datadir."Module";
>
>everything works again.

I don't know how "everything works".  You haven't changed the problem at
all.  That gives me a syntax error.  And even if it didn't, you haven't
changed the fact that 'use' is using $datadir, which HAS NOT BEEN DEFINED
yet.

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: use lib problem

2003-08-02 Thread awarsd
Hi,

I messed around and found that
if in config i do $datadir = "/my/path/";
instead o f$datadir= "/my/path";

then in my script i do
#!/usr/bin/perl
require 'config.pl';
use $datadir."Module";

everything works again.
Thanx for the suggestion tough because i didn't know how to use BEGIN now i
do :-

Awards



"Jeff 'Japhy' Pinyan" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On Aug 2, awarsd said:
>
> >use lib "/path/to/Module";
> >it works just fine
>
> >with $dir = '/path/to';
> >use lib "$dir/Module";
> >it give me an error I also tried use lib qw() but same problem is there a
> >way to fix the problem??
>
> The problem is that 'use' is a compile-time directive, whereas assigning a
> value to $dir happens at run-time.
>
> When Perl runs your program, it does a preliminary sweep over it, and does
> things like include modules when 'use'd, and execute BEGIN blocks.
>
> A statement like 'use lib "..."' is really just
>
>   BEGIN {
> require lib;
> lib->import("...");
>   }
>
> so it happens at compile-time.  This means that your variable $dir, which
> gets assigned at run-time, won't have a value when you need it to.  Here's
> a simple demonstration:
>
>   $x = 2;
>   BEGIN {
> print "x is '$x'\n";
>   }
>
> That prints "x is ''", because the BEGIN block happens before we set $x to
> 2.  You probably want to require() your config file in a BEGIN block
> before you do 'use lib'.
>
>   BEGIN { require "my_vars.pl" }
>   use lib "$dir/...";
>
> -- 
> Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
> RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
>  what does y/// stand for?   why, yansliterate of course.
> [  I'm looking for programming work.  If you like my work, let me know.  ]
>



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: use lib problem

2003-08-02 Thread Jeff 'japhy' Pinyan
On Aug 2, awarsd said:

>use lib "/path/to/Module";
>it works just fine

>with $dir = '/path/to';
>use lib "$dir/Module";
>it give me an error I also tried use lib qw() but same problem is there a
>way to fix the problem??

The problem is that 'use' is a compile-time directive, whereas assigning a
value to $dir happens at run-time.

When Perl runs your program, it does a preliminary sweep over it, and does
things like include modules when 'use'd, and execute BEGIN blocks.

A statement like 'use lib "..."' is really just

  BEGIN {
require lib;
lib->import("...");
  }

so it happens at compile-time.  This means that your variable $dir, which
gets assigned at run-time, won't have a value when you need it to.  Here's
a simple demonstration:

  $x = 2;
  BEGIN {
print "x is '$x'\n";
  }

That prints "x is ''", because the BEGIN block happens before we set $x to
2.  You probably want to require() your config file in a BEGIN block
before you do 'use lib'.

  BEGIN { require "my_vars.pl" }
  use lib "$dir/...";

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: use lib problem

2003-08-02 Thread Li Ngok Lam

- Original Message - 
From: "awarsd" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, August 02, 2003 10:01 PM
Subject: use lib problem


> Hi,
>
> I have a problem maybe it is normal.
> My problem is with using lib
> now to retrieve my module i do this
> use lib "/path/to/Module";
> it works just fine
> but created a configuration file.
> with $dir = '/path/to';
> and when i do
> use lib "$dir/Module";
> it give me an error I also tried use lib qw() but same problem is there a
> way to fix the problem??
>
> regards
> awards
>

I am not sure, but I bet a guess, "use" is activated at comiple time, that
means
use "$dir/Module" is still going earlier than $dir = "path/to" even the
declaration
of $dir is going earlier than use lib...

In case if you want to do this, you may try ;
package blah;

BEGIN{ $dir = "path/to" }
use lib "$dir/Module";

1;





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



use lib problem

2003-08-02 Thread awarsd
Hi,

I have a problem maybe it is normal.
My problem is with using lib
now to retrieve my module i do this
use lib "/path/to/Module";
it works just fine
but created a configuration file.
with $dir = '/path/to';
and when i do
use lib "$dir/Module";
it give me an error I also tried use lib qw() but same problem is there a
way to fix the problem??

regards
awards



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]