Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by esskar (Deacon)
on Jun 29, 2006 at 06:08 UTC ( #558226=note: print w/ replies, xml ) Need Help??


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

well, it is just a WARNING, and nothing you must care about. it' beacuse you are using require to import the module. There is already a bug-report-ticket issued on that "problem".

below, you find a cleaned up version.
#!/usr/bin/perl use strict; use warnings; if ( $^O =~ /^(MS)?Win/ ) { eval { require Win32::DriveInfo; my $TotalNumberOfFreeBytes = (Win32::DriveInfo::DriveSpace('c: +'))[6]; my $TotalNumberOfBytes = (Win32::DriveInfo::DriveSpace('c:'))[ +5]; print "This is $^O \n"; print "Total Free: $TotalNumberOfFreeBytes\tTotal size: $Total +NumberOfBytes\n"; }; print $@, "\ndone!"; } elsif ( $^O =~ /^linux/ ) { print "This is Linux OS!!!\n"; }


Comment on Re: How to execute succcessful this Perl script in Linux, window and solaris?
Download Code
Re^2: How to execute succcessful this Perl script in Linux, window and solaris?
by esskar (Deacon) on Jun 29, 2006 at 06:15 UTC
    another thing. if you do not need STDERR you can do a dirty trick! ;)
    #!/usr/bin/perl -w use strict; use warnings; if ( $^O =~ /^(MS)?Win/ ) { eval { #dirty hack to avoid the warning close STDERR; require Win32::DriveInfo; my $TotalNumberOfFreeBytes = (Win32::DriveInfo::DriveSpace('c: +'))[6]; my $TotalNumberOfBytes = (Win32::DriveInfo::DriveSpace('c:'))[ +5]; print "This is $^O \n"; print "Total Free: $TotalNumberOfFreeBytes\tTotal size: $Total +NumberOfBytes\n"; }; print $@, "\ndone!"; } elsif ( $^O =~ /^linux/ ) { print "This is Linux OS!!!\n"; }
    HTH

      close(STDERR) affects the whole program. There are better ways of suppressing warnings: (best to worse)

      • { no warnings 'warningtype'; ... } (Compile- and run-time, specific)
      • { no warnings; ... } (Compile- and run-time, broad)
      • { local $SIG{__WARN__} = {}; ... } (Run-time, broad)
      • { local *STDERR; ... } (Run-time, broad, has side effects.)

      And you're only hiding the symptom, not fixing the problem. Like the warning says, a piece of code that should get executed is not getting executed.




        Thanks all the Perl senior!!!! (^o^)...


Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2015-07-03 07:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (48 votes), past polls