Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Win32::Daemon::State returns a 0 or 1

by Intrepid (Deacon)
on Jan 06, 2009 at 01:08 UTC ( [id://734323]=note: print w/replies, xml ) Need Help??


in reply to Win32::Daemon::State returns a 0 or 1

You (azaragoza) wrote:
When I run the code instead of returning something like, SERVICE_START_PENDING, it returns a zero or a one. Thanks for your help.

SERVICE_START_PENDING and the other CAPitalized items are capitalized because they are constants. They are preprocessor macros that are defined in the C/C++ API for the MS Windows systems under discussion.

Perl customarily uses a convention to represent such preprocessor macros. Since Perl isn't C or C-like, it does not use a preprocessor. Instead, these tokens are exported from the module as constant subroutines, ones which have names that are in all-caps. See the constant.pm documentation. A constant subroutine is syntactically a subroutine but it always returns the same value (and so the Perl parser, which is a very smart parser, reduces the subroutine call to a simple constant in the compilation phase).

You have been suitably punished for not using strict; in your code, and will go on being punished in many others ways as long as you reject or forget this basic level of Perl wisdom (punished by not being told by Perl that you were saying something nonsensical; your constants were being seen as barewords that were interpreted as sloppy unquoted strings because you neglected strict). If you had used strict you would have seen that some subroutines were undefined and therefore compilation was aborted.

This satisfying form of Instance Justice (to quote Damian Conway) is visited on Perl users who try to get by with merely emulating what they think is the code needed to use a sophisticated interface module - faking it IOW - instead of getting serious and doing things the smart way at each level, from simple and basic like "use strict; use warnings;" to each level upwards in complexity and specialization. To do things the smart way you have to study and learn what the smart way is, and then put it into practice in each piece of code you write. You have to learn Perl in other words.

HTH

Replies are listed 'Best First'.
Re^2: Win32::Daemon::State returns a 0 or 1
by azaragoza (Acolyte) on Jan 06, 2009 at 20:16 UTC
    I humble myself, as unworthy of the great perl coding language and before you oh great indegnant one, but I down loaded this code from the internet and was trying to run it as is so I would not screw it up, but it's not working, so I so humbly asked your wisdom. I added "use strict;" and "use warnings;" and it gave no errors or warnings. Please do not chastise me for my ignorance of perl, I'm trying to learn it by downloading scripts from the web and then trying to apply them.
      If you're playing with the same script I was you may be having the same problem I did. :) You need to include the following: use Win32::Daemon; I had win32::Daemon; which, naturally, did not work. Also, your installation may well not have Daemon, in which case you will need to get it and install (through ppm).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-03-29 00:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found