Fellow monks...

While I am not having a problem with this script specifically, I was hoping to have some comments about what I had written, perhaps a better way to do something, perhaps a hidden bug. Either way, I will go over some of the code that I had specific questions about and focus on those areas. If you want to read the entire program, its only ~500 lines.

Overview

This script is deisgned to parse a .csv file containing a part#, a description and a price, sorted by category. Once the file is parsed, the part numbers are compared to a list of part numbers already contained in a database. New parts are added to the database and marked as a "new arrival". Existing parts have their price updated and parts that are in the database but no longer in the parts list are deleted.

line 419

# bad kludge, I haven't figured out how to handle this, but # if the query doesn't return anything, this function fails; if($query =~ /SELECT/i) { $return_data = $sth->fetchall_arrayref(); }

Here I'm trying to abstract some of the database implementation by creating a function that takes in a query string and an argument list and returns the results, if there are any. Unfortunatly, when I try to call fetchall_arrayref after performing a SELECT query, it dies on me. So, I make this quick hack to see if the query contains the word "select". I would like to do this better, but I'm not quite sure how.

line 230

sub update_price { # get reference to hash and algorithm for updating parts. my ($price, $price_algo) = @_; #TODO lookup return values for eval eval $price_algo or die( __LINE__ . "Err: $! \n$@\n"); return $price; }

This is part of my design for updating the price on a sliding scale or only under certain conditions. For example, I want to update prices that are over $100 by $15 and anything under, by only $5. My solution was to eval a statement that sets the $price variable. How safe is this? I only expect people who have an account to use this, so they have access to Perl already. Also, is there any more checking I should be doing to make sure the eval statement execute properly?

line 78

my %items = parse_input($options{u}, $parts_algo);

This last one is kind of vague, but the problem is, parse_input doesn't do anything with $parts_algo, it just passes it off to the update_price function. I was trying to come up with a better way of doing this... maybe breaking up parse_input a little, but I hadn't really thought of anything.

Other then that, please take a look at the rest of the code, and if there are any things you would change, please let me know, I'm still pretty green.

Thanks
--
Ben
"Naked I came from my mother's womb, and naked I will depart."


In reply to Code review and question for parts script by bprew

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.