Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Another noob making a mess of variable scope....

by walto (Pilgrim)
on Feb 18, 2014 at 17:28 UTC ( [id://1075361]=note: print w/replies, xml ) Need Help??


in reply to Another noob making a mess of variable scope....

If you want a more object oriented approach you can modify App::Config like this
#!/usr/bin/perl # # use strict; use warnings; package AppConfig; use 5.014; use strict; use warnings; use autodie; use Carp; use Exporter qw(import); # Module specific imports use XML::Twig; our $VERSION = 1.00; our @ISA = qw(Exporter); our @EXPORT_OK = qw(getAppConfig); our %EXPORT_TAGS = ( 'all' => \@EXPORT_OK, ); sub new { my $class = shift; my $self = {}; my %passed_params = @_; croak "Please provide filename\n" unless (defined $passed_params{f +ilename}); $self->{filename}= $passed_params{filename}; bless( $self, $class ); return $self; } sub getAppConfig { my ($self) = @_; my ( %config, $twig, $root ); $twig = XML::Twig->new(); $twig->parsefile->( $self->{filename} ); $root = $twig->root; $config{'ppSK'} = $root->first_child('pp')->first_child('ppSK')->text; return \%config; } # End..... 1;

And use the module like this
#!/usr/bin/perl use 5.014; use strict; use warnings; use autodie; use AppConfig qw(:all); use Data::Dumper; my $app_config = AppConfig->new('filename' => '/home/john/tmp/config.x +ml'); my %config=getAPPConfig();

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2026-01-15 14:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (118 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.