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

Re4: Some suggestions on coding style - a chance to critique

by dragonchild (Archbishop)
on Jul 01, 2002 at 18:55 UTC ( #178640=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Re: Some suggestions on coding style - a chance to critique
in thread Some suggestions on coding style - a chance to critique

using constant is a very good thing to do. However, if you don't know what constant is doing, you can be very surpsised.

use constant LOG_DIRECTORY => '/foo/bar/baz'; # Equivalent to sub LOG_DIRECTORY () { '/foo/bar/baz' }
The most obvious problem is interpolation in double-quoted strings.

Similarly, you can't use LOG_DIRECTORY as the key to a hash, because it's not a C-style preprocessor declaration, but a function declaration.

Just, be careful and know what is happening under the hood.

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.


Comment on Re4: Some suggestions on coding style - a chance to critique
Download Code
Replies are listed 'Best First'.
Re5: Some suggestions on coding style - a chance to critique
by blakem (Monsignor) on Jul 01, 2002 at 21:03 UTC
    Doh! Nevermind....

    I can see the interpolation problem, but whats this about not using a constant as a hash key?

    #!/usr/bin/perl -w use strict; use constant LOG_DIRECTORY => '/foo/bar/baz'; my %hash; $hash{LOG_DIRECTORY} = 'happy'; print "log directory ${\LOG_DIRECTORY} is $hash{LOG_DIRECTORY}\n"; __END__ produces: log directory /foo/bar/baz is happy

    -Blake

Re: Re4: Some suggestions on coding style - a chance to critique
by Anonymous Monk on Jul 01, 2002 at 22:14 UTC
    Try printing out the keys of %hash. You just assigned the value "happy" to the key "LOG_DIRECTORY". To use the constant LOG_DIRECTORY as the key you need to explicitly use it as a function.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (11)
As of 2015-07-30 14:50 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 (271 votes), past polls