I was modifying one of our processes today and I came across some bizarre behavior. Essentially, the process reads in a flat configuration file which contains data like
stored_proc_list => [ 'sproc1', 'sproc2', 'sproc3' ]
update_stats_xref => { 'sproc2' => 'update_table2' }
logfile => somefile.txt
and converts them into Perl variables (array ref, hash ref, and scalar respectively) using an eval statement. When I tried to update the code to allow for scalar references (which would immediately get converted into a scalar), it started to core dump on me. I have included the offensive code below, stripped down to what appears to be its barest elements. Essentially I have a string, which gets turned into a Scalar reference when I eval it, which I then try to assign back into the same value. If I do a Scalar assignment, it blows up. If I do a list assignment, it works just fine.
I was hoping that someone out there can explain this behavior to me. I have already found a working solution, but I was curious as to why it works (or doesn't) the way it works.
Note: I have tried this on both NT 4.0 (which I where I do most of my development :< ) and on AIX.
my $temp_value = q(\'/Path/to/log.txt');
my $value = eval $temp_value;
# This one results in no value for $value and coredumps
$value = $$value;
print "New \$value = $value\n";
# This one does what I want it to do
( $value ) = ( $$value );
print "New \$value = $value\n";
Thanks for any insight,
Mike
mppennucci@delinvest.com
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.