I'm writing a script which adds a string in records in one file, based on the presence of a part number in a second file. Basically, I search the first file, and whenever I find the flag I want, I add it to a hash like so:
$part_file{$pf_columns[0]} = 'Y';
$pf_columns[0] contains a string with the part number. Later on, I iterate over the lines of the second file. I grab the part number, and do something like this:
if (exists $part_file{$partnum})
{
do_this();
}
The problem is, the
if() block never runs. If I replace the
exists with
defined it still doesn't work. Now, if I replace the
$part_file{$partnum} with
$part_file{"SOME_PART_NO"} it works fine, for every line of the file. If I print out
keys %part_file, then all the part numbers are there.
What am I missing here?
Thanks,
--J
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.