CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
More questions re: NT-Unix port

 



tschau
Novice

Aug 7, 2005, 7:12 AM

Post #1 of 5 (594 views)
More questions re: NT-Unix port Can't Post

I have some more questions regarding the above, and would appreciate an answer from the experts out there:

1. How do I make the .pm files available to my PERL programs? In other words, how do I add a folder to the @INC array? I tried exporting a folder name to perl5lib (the way I do in the NT environment), but that did not work.

2. I am trying to calculate the elapsed time taken by a process using the "Time::HiRes" function. The way I am doing now is far from pretty:

a) I created a perl script to return the current date/time and another one to format the elapsed time.
b) My unix test script goes something like this:

>>>>>>>>>>>>>>>>>>>>>>
typeset start=`datetime.pl`
sleep 35
typeset end=`datetime.pl`
typeset elapsed=`elapsed.pl $start $end`
echo "Elapsed time: $elapsed"
>>>>>>>>>>>>>>>>>>>>>>

It would be really nice if I could put both datetime.pl and elapsed.pl as routines inside one single file and make them accessible from within the script. Is there any way to do this?

Thanks for your attention and help!


davorg
Thaumaturge / Moderator

Aug 7, 2005, 9:57 AM

Post #2 of 5 (592 views)
Re: [tschau] More questions re: NT-Unix port [In reply to] Can't Post

You can add new directories to @INC using "use lib". This should work the same way on any platform.

It's almost certainly possible to combine your external programs into routines that can be called from within your main program - but without seeing the code it's hard to offer any real help.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


tschau
Novice

Aug 7, 2005, 11:40 AM

Post #3 of 5 (588 views)
Re: [davorg] More questions re: NT-Unix port [In reply to] Can't Post

Thanks for your reply.

I have included all the files in order for you to get the complete picture.

"Unix script" is the main script, which calls datetime.pl to get the current date/time. It also calls elapsed.pl to get the elapsed time. Things work after a fashion coded this way. However, what I would like to see is somehow make Datetime.pm available to the unix script, so that the routine calc_elapsed can be invoked directly. Taking this one step further, I would have one file including several PERL routines, and they would be all available to my unix scripts.

Regarding my first question, when you say "use lib" did you mean something like "use Datetime;" inside the PERL script? I tried that and here is the error I got:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Can't locate Datetime.pm in @INC (@INC contains: /usr/opt/perl5/lib/5.8.2/aix-th
read-multi /usr/opt/perl5/lib/5.8.2 /usr/opt/perl5/lib/site_perl/5.8.2/aix-threa
d-multi /usr/opt/perl5/lib/site_perl/5.8.2 /usr/opt/perl5/lib/site_perl .) at pe
rltest line 2.
BEGIN failed--compilation aborted at perltest line 2.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

The only case where "use" will work is if the .pm file is in the current folder, and it does not look like this has anything to do with the PATH setting either.

Hope the above is clear. Thanks once again for your help.
Attachments: unix script.ksh.txt (0.14 KB)
  datetime.pl (61 B)
  elapsed.pl (0.32 KB)
  Datetime.pm (0.39 KB)


davorg
Thaumaturge / Moderator

Aug 7, 2005, 12:01 PM

Post #4 of 5 (586 views)
Re: [tschau] More questions re: NT-Unix port [In reply to] Can't Post


In Reply To
Regarding my first question, when you say "use lib" did you mean something like "use Datetime;" inside the PERL script?


No, I mean adding code like:


Code
use lib '/path/to/your/library/dir';


to your program.

How did you install Datetime.pm? And where is it?

Oh, and by the way, it's "Perl" not "PERL".

I'll look at your code and reply to it later (maybe not today).

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


tschau
Novice

Aug 7, 2005, 12:47 PM

Post #5 of 5 (583 views)
Re: [davorg] More questions re: NT-Unix port [In reply to] Can't Post

Thanks for correcting my error. If Larry Wall put "Perl" in the title of his book, then it must be the correct way of spelling it. I just never noticed, and went by the assumption that since it was an acronym, all letters would be capitalized. Live and learn...

Thanks for your hint, I resolved the problem of getting the .pm files from the folder I want.

Thanks.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives