Passing Main script variables into Perl Modules

前端 未结 1 1650
花落未央
花落未央 2021-01-29 10:03

I am writing a Perl script that is run by a user and makes use of the current Linux environment as variables and other variables as well. The environment settings may change and

相关标签:
1条回答
  • 2021-01-29 10:43

    The environment variables are accessible from anywhere in the global %ENV hash:

    print $ENV{HOME};
    

    If you are creating objects, they probably have some attributes (being the objects hashes, arrays or even inside out objects...) Just store the relevant values into the attributes, e.g.

    my $obj = Some::Package->new( name    => 'Homer',
                                  surname => 'Simpson',
                                  city    => 'Springfield',
                                  # ... 7 more
                                );
    
    0 讨论(0)
提交回复
热议问题