punkish has asked for the wisdom of the Perl Monks concerning the following question:
I have spent the past few days working with Win32::Daemon. I have been using code (from the docs and examples provided) that looks like so
Q1. What is this use of barewords? I almost feel compelled to single quote all the words in UPPERCASE above. Should this not be 'SERVICE_STOPPED' etc.? And won't this fail under use strict?while( SERVICE_STOPPED != ( $State = Win32::Daemon::State() ) ){ if( SERVICE_STARTING == $State ) {
Q2. Are the UPPERCASE words above just proxy for numbers? For example, in the situation above, the State() returned is actually a number. Of course, having the -w switch on complains that
Argument "SERVICE_STARTING" isn't numeric in numeric eq (==) at ...
Q3. (this one is the style-related question) I feel the urge to reverse the above tests as in
since I am used to testing the value that a variable holds against certain "measures" that are fixed as inif( $State == SERVICE_STARTING )
if ($color eq 'red') { print 'angry'; } elsif ($color eq 'green') { print 'money'; } elsif ($color eq 'blue') { print 'sad'; }
I guess this is new idiom for me, and I need to understand what is going on here.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Barewords and equality tests
by davido (Cardinal) on Dec 29, 2004 at 22:44 UTC | |
by punkish (Priest) on Dec 29, 2004 at 22:56 UTC | |
|
Re: Barewords and equality tests
by bart (Canon) on Dec 29, 2004 at 22:46 UTC | |
|
Re: Barewords and equality tests (())
by tye (Sage) on Dec 30, 2004 at 01:36 UTC | |
|
Re: Barewords and equality tests
by dave_the_m (Monsignor) on Dec 29, 2004 at 22:44 UTC | |
by Old_Gray_Bear (Bishop) on Dec 29, 2004 at 23:03 UTC |