Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > loading a module dependant on the OS

Reply
Thread Tools

loading a module dependant on the OS

 
 
Guest
Posts: n/a
 
      06-30-2003
I have a Perl script which runs under Windows and uses the module
Win32:rocess, I now have a need to run this on Linux.

I can do produce two scripts on for each platform, which would be a pain to
maintane.

My question being how can I have a script on Linus that has

use Win32:rocess;

since this module does not exist I get a compilation error. I thought I
could use the $^O variable but my little knowledge fails to supply the
answer.

I assume this is a common problem so will have an answer. If you can point
me in the direction of a README or HOW_TO document I would be greatful.

Richard.





 
Reply With Quote
 
 
 
 
Brian McCauley
Guest
Posts: n/a
 
      06-30-2003
<(E-Mail Removed)> writes:

> use Win32:rocess;
>
> since this module does not exist I get a compilation error. I thought I
> could use the $^O variable but my little knowledge fails to supply the
> answer.


Since you have a question about use please read at least the first
paragraph of:

perldoc -f use

Write the "use" out long-hand and then apply the knowledge already
have. That should supply the answer.

Surely this should be in the FAQ!

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
 
Reply With Quote
 
 
 
 
Rohan Romanus Almeida
Guest
Posts: n/a
 
      06-30-2003

<(E-Mail Removed)> thus wrote:
> use Win32:rocess;
>
> since this module does not exist I get a compilation error. I thought I
> could use the $^O variable but my little knowledge fails to supply the
> answer.
>


You can do an "eval" before the use.

Look at this example:
<code>
$useReadKey = 0;
eval q/use Term::ReadKey/;
if (!$@) {
# Term-ReadKey module is installed
$useReadKey = 1;
}
</code>

--
arc_of_descent

 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      06-30-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
>
> use Win32:rocess;
>
> since this module does not exist I get a compilation error. I
> thought I could use the $^O variable


You can:

BEGIN { require Win32:rocess if $^O eq 'MSWin32' }

/ Gunnar

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

 
Reply With Quote
 
Guest
Posts: n/a
 
      06-30-2003
Thanks for the solution I forgot all about eval.

Richard.


"Rohan Romanus Almeida" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) t...
>
> <(E-Mail Removed)> thus wrote:
> > use Win32:rocess;
> >
> > since this module does not exist I get a compilation error. I thought I
> > could use the $^O variable but my little knowledge fails to supply the
> > answer.
> >

>
> You can do an "eval" before the use.
>
> Look at this example:
> <code>
> $useReadKey = 0;
> eval q/use Term::ReadKey/;
> if (!$@) {
> # Term-ReadKey module is installed
> $useReadKey = 1;
> }
> </code>
>
> --
> arc_of_descent
>



 
Reply With Quote
 
Guest
Posts: n/a
 
      06-30-2003
Oh wow that was so easy, thanks.

I'll go read the camel book again.

Richard.

"Gunnar Hjalmarsson" <(E-Mail Removed)> wrote in message
news:bdph9k$tpcot$(E-Mail Removed)...
> (E-Mail Removed) wrote:
> >
> > use Win32:rocess;
> >
> > since this module does not exist I get a compilation error. I
> > thought I could use the $^O variable

>
> You can:
>
> BEGIN { require Win32:rocess if $^O eq 'MSWin32' }
>
> / Gunnar
>
> --
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating runnable .jar with dependant libraries? Bas Java 2 05-04-2006 07:23 PM
testing -- what to do for testing code with behaviour dependant uponwhich files exist? Brian van den Broek Python 3 04-03-2005 12:28 AM
Dependant files query KiwiBrian HTML 2 10-16-2004 12:33 PM
Problems using freeze with platform dependant compiles Jeff Smith Python 1 07-29-2004 02:26 PM
image dependant on resolution Michael Tonelli HTML 11 07-23-2004 05:01 PM



Advertisments