Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: How to execute succcessful this Perl script in Linux, window and solaris?

by shmem (Chancellor)
on Jun 29, 2006 at 06:03 UTC ( [id://558225]=note: print w/replies, xml ) Need Help??


in reply to How to execute succcessful this Perl script in Linux, window and solaris?

Maybe this happens because you use require instead of use, thus no import.

update - been too dizzy this morning :-(

Turn the eval block into a string eval and wrap it in a BEGIN block. This way the eval is executed and the module loaded before the call to Win32::DriveInfo::DriveSpace is even compiled. I can't test, because I don't have a Windows box at hand.

Put this at the very beginning of your script:

BEGIN { if ($^O =~ /^(MS)?Win/) { eval "use Win32::DriveInfo"; die $@ if $@; } }

What happens if you turn the eval block into a string eval? I can't test, because I don't have a Windows box at hand.

if ( $^O =~ /^(MS)?Win/ ) { eval "use Win32::DriveInfo"; $TotalNumberOfFreeBytes = (Win32::DriveInfo::DriveSpace('c:'))[6]; $TotalNumberOfBytes = (Win32::DriveInfo::DriveSpace('c:'))[5]; print "This is $^O \n"; print "Total Free: $TotalNumberOfFreeBytes\tTotal size: $TotalNumb +erOfBytes\n"; print $@,"\ndone!"; } elsif ( $^O =~ /^linux/ ) { print "This is Linux OS!!!\n"; }

--shmem

update: changed "require" to "use" in the string eval. Small negligence after copy & paste.

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^2: How to execute succcessful this Perl script in Linux, window and solaris?
by esskar (Deacon) on Jun 29, 2006 at 06:09 UTC
    makes no difference. It is still a require.
      I actually meant use. I forgot to change 'require' to 'use' after copy & paste. Fixed. You could have /msg'ed me, btw ,-)
Re^2: How to execute succcessful this Perl script in Linux, window and solaris?
by ikegami (Patriarch) on Jun 29, 2006 at 07:15 UTC

    Update: While trying to reproduce the problem minimally, I realized I misunderstood what I read earlier or what I read was wrong. Disregard this post.

    I don't have that module, but I don't see how your solution could work. Win32::DriveInfo::DriveSpace('c:') is still being compiled before use Win32::DriveInfo; is executed, so the prototype mismatch is still present.

      Darn... too early in the morning.

      what I really meant is the following at the very beginning of the script:

      BEGIN { if ($^O =~ /^(MS)?Win/) { eval "use Win32::DriveInfo"; } }

      Thanks for another slap ;-)

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

        That does the trick.

        # Module.pm package Module; INIT { print("ok\n"); } 1;
        >perl -we "use Module" ok >perl -we "require Module if $^O =~ /Win/" Too late to run INIT block at Module.pm line 3. >perl -we "eval 'use Module' if $^O =~ /Win/" Too late to run INIT block at Module.pm line 3. >perl -we "BEGIN { eval 'use Module' if $^O =~ /Win/ }" ok

        Update: The if pragram is useful here:

        >perl -we "use if $^O =~ /Win/, 'Module'" ok

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://558225]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-19 13:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found