Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by walto (Pilgrim)
on Feb 18, 2014 at 17:28 UTC ( #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
Node Status?
node history
Node Type: note [id://1075361]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2021-01-23 20:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?