frodo2014 has asked for the wisdom of the Perl Monks concerning the following question:
and my .pm#!/usr/bin/perl use 5.014; use strict; use warnings; use autodie; use AppConfig qw(:all); use Data::Dumper; $AppConfig::configFile='/home/john/tmp/config.xml'; my %config=getAPPConfig();
Now... when I run it, I get this....#!/usr/bin/perl package AppConfig; use 5.014; use strict; use warnings; use autodie; 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, ); our $configFile; sub getAppConfig { my (%config,$twig,$root); say $AppConfig::configFile; $twig = XML::Twig->new(); $twig->parsefile->($AppConfig::configFile); $root = $twig->root; $config{'ppSK'}=$root->first_child('pp')->first_child('ppSK')->text; return \%config; } # End..... 1;
So the variable scope seems to be ok because "say $AppConfig::configFile;" outputs.... but then the same variable passed to XML::Twig seems to cause all hell to break loose. So here I am, submitting myself to the lions as another newbie to be devoured./home/john/tmp/config.xml Use of uninitialized value in -f at /usr/share/perl5/XML/Twig.pm line +697. Couldn't open : No such file or directory at AppConfig.pm line 30 at AppConfig.pm line 30
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Another noob making a mess of variable scope....
by toolic (Bishop) on Feb 17, 2014 at 15:23 UTC | |
|
Re: Another noob making a mess of variable scope....
by tobyink (Canon) on Feb 17, 2014 at 16:04 UTC | |
|
Re: Another noob making a mess of variable scope....
by frodo2014 (Initiate) on Feb 17, 2014 at 21:09 UTC | |
|
Re: Another noob making a mess of variable scope....
by walto (Pilgrim) on Feb 18, 2014 at 17:28 UTC | |
|
Re: Another noob making a mess of variable scope....
by fishmonger (Chaplain) on Feb 17, 2014 at 16:18 UTC |