Do you know where your variables are? | |
PerlMonks |
Re: Win32::Daemon::State returns a 0 or 1by Intrepid (Deacon) |
on Jan 06, 2009 at 01:08 UTC ( [id://734323]=note: print w/replies, xml ) | Need Help?? |
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
In Section
Seekers of Perl Wisdom
|
|