Thanks Rob, this worked just perfect. Yes, you picked the right first name, thanks allot.

-Mahdi.


Rob Dixon wrote:

Mahdi A Sbeih wrote:
> Hi there,
>
> I have a perl script that will run on both Unix and Windows platforms,
> the only problem I am having is below:
>
> use Win32::Process;
>
> I have to use the above only for windows since later in my script:
> if ($platform eq 'UNIX') {
>            system("$Cmd > /dev/null 2>&1 &");
> }
>        elsif ($platform eq 'WINDOWS') {
>            Win32::Process::Create($process,"$^X","$^X" . " $Cmd",0,
> CREATE_NO_WINDOW, ".") || die $!;
> }
>
>
> I don't want to maintain two scripts, and it seems I cann't do something
> like this on the top of the script:
> if ($platform eq 'WINDOWS') {
>    use Win32::Process;
> }
>
>
> Anyone can help?
>
> NOTE: regarding the above platform variable, it is defined on the top of
> the script:
> ($^O =~ /Win32/) ? ($platform = 'WINDOWS') : ($platform = 'UNIX');

Hello Mahdi (have I picked the right first name?)

A call to 'use' can't be put within a conditional, but one to 'require' can.
Simply replace

  use Win32::Process;

with

  BEGIN {
    if ($^O eq 'MSWin32') {
      require Win32::Process;
      Win32::Process->import;
    }
  }

and you should be fine.

HTH,

Rob



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to