Hey folks: This one has me stumped. I've getting debugging output that looks like this:
$key is |dbhost| and $value is |localhost.localdomain| or |localhost.l +ocaldomain|. localhost.localdomain $key is |dbuser| and $value is |user| or |user|. user
but then:
Use of uninitialized value in string at ./cache-riding-pages.pl line 2 +6. Use of uninitialized value in string at ./cache-riding-pages.pl line 2 +7. Use of uninitialized value in string at ./cache-riding-pages.pl line 2 +8. Use of uninitialized value in string at ./cache-riding-pages.pl line 2 +9.
produced by code that looks something like:
#!/usr/bin/perl -w use strict; use DBI; my(%conf); my $config = "/path/to/conf/config.php"; my($dbh,$sql,$sth,$key,$value); open(CONF,$config); while (<CONF>) { if(m/\=/ && m/db/){ ($key,$value) = split(/ \= /,$_); chomp($key); chomp($value); $key =~ s/\$//; $value =~ s/\"//g; $value =~ s/\;//; $conf{'$key'} = $value; print "\$key is |$key| and \$value is |$value| or |$conf{'$key'}|. +\n"; print $conf{'$key'}; } } close CONF; # values %conf; # $dbh = ed_connect($conf{'dbhost'}, $conf{'dbname'}, $conf{'dbuser'}, + $conf{'dbpass'}); print "$conf{'dbhost'}"; print "$conf{'dbname'}"; print "$conf{'dbuser'}"; print "$conf{'dbpass'}"; # $dbh = connect('localhost', $conf{'dbname'}, $conf{'dbuser'}, $conf{ +'dbpass'}); exit; 1; sub ed_connect { my($host_name,$db_name,$db_user,$db_pass)=@_; my $dsn = "DBI:mysql:host=$host_name;database=$db_name"; return (DBI->connect($dsn,$db_user,$db_pass), {PrintError => 0, RaiseError => 1}); }
So my question is this: What happened to my %conf hash values when the CONF file handle got closed? All help is appreciated. Thank you for your time and consideration. -- Hugh

In reply to Disappearing hash values by hesco

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.