Is there some conviented way to use one constant when defining another constant in perl?
The following obviously does not work
use constant {
    MAIN_DIR   => "/path/to/some/dir",
    PROP_DIR => MAIN_DIR . "/sub_dir",
    PROP_FILE  => PROP_DIR . "/props.props",
};
The开发者_如何学JAVA only think I could think of is multiple use constant lines, but it's a bit ugly...
FYI, you can use constant functions in the first place (that's how the constants pragma works):
sub MAIN_DIR  () { "/path/to/some/dir"       }
sub PROP_DIR  () { MAIN_DIR . "/sub_dir"     }
sub PROP_FILE () { PROP_DIR . "/props.props" }
According to perldoc there is no way around that. At least not with use constants.
I'd go with using multiple use statements.
$ perl -wle 'use Readonly; Readonly my $FOO => "foo"; Readonly my $FOOBAR => $FOO . "bar"; print $FOOBAR;'
foobar
PBP (Perl Best Practices) recommends using Readonly
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论