Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Retrieve value with key warns 'unitialized value' although presentby strawberrysocialist (Initiate) |
on Dec 28, 2009 at 17:28 UTC ( [id://814634]=perlquestion: print w/replies, xml ) | Need Help?? |
strawberrysocialist has asked for the wisdom of the Perl Monks concerning the following question: First, I'm new to perl and am still working through Learning Perl 5th ed., in chapter 11. However, I've used both VBA and VB.Script a lot and some VB.Net so I'm not new to programming entirely. OverviewI'm writing a simple backup program (backup.pl) using rsync to a home server running ubuntu jaunty. I have a configuration file (backup.conf) that stores the details for rsync. I wrote my own code, sub load_config, to process the configuration file. (NOTE: I did this in lieu of using a CPAN module since I'm using cygwin on Win XP and could not get CPAN modules to install.) The sub processes the config file and uses the hash declared in the main procedure to store the keys and values. ProblemWithin the load_config sub I can retrieve the value for a key and print the entire hash out iteratively. Within the main procedure I can print the entire hash out iteratively but CAN NOT retrieve the value for a key. No matter how I try to use the key (no quotes, single or double quotes, assigning to a variable first) I'm warned about an 'unitialized value' and get nothing but an empty string. EffortsI've tried googling and PerlMonks' super search but probably couldn't find the answer because of poor search terms. I found several tutorials and examples. Some of these use a bareword key within the braces, { }, others use double quotes, and a few use single quotes, providing I'm reading them correctly. I think it must be a syntax issue since I can iterate over the hash within the scope fo the main procedure, just not retireve the value using the key, both of which I can do within the subprocedure. I'm just puzzled and no doubt my lack of perl knowledge is hampering my ability to find the solution. I was tempted to throw my laptop around last night--way too tired and frustrated. I'd appreciate any help that points me in the right direction. The actual code and config data follow. FilesScript file -- backup.plThis is an excerpt but contains all the code at issue
Config file -- backup.conf
Back to
Seekers of Perl Wisdom
|
|