Hope you guys will be able to help me out on this one, still new to Perl and working it out as a go !?! I'm reading a CSV File and storing the fields into variables. The CSV data can contain empty fields. These are being treated by Perl as undefined variables - which is what I believe is Perl's interpretation of NULL. I want to be able to write these undefined variables to my table (using DBI) which will then be stored as NULL values on my table. The code below is the segment updating the Database... whole script is 600 lines long so best not to post it all!
# INSERT RECORD INTO MET_OFFICE_RAW_DATA TABLE no warnings 'uninitialized'; my $mo_raw_sql = "REPLACE INTO met_office_raw_data SET observation_datetime_utc = '$file_o +bs_datetime_utc', observation_datetime_local = '$file_obs_d +atetime_local', observation_datetime = '$file_obs_ +datetime', station_id = '$file_stati +on_id', station_name = '$file_station_ +name', temp_c = '$file_temp_c', dewpoint_c = '$file_dewpoint_c +', humidity_rh = '$file_humidity_ +rh', wind_dir_compass = '$file_wind_dir +_compass', wind_speed_mph = '$file_wind_s +peed_mph', wind_gust_mph = '$file_wind_gu +st_mph', visibility_metres = '$file_visibil +ity_metres', pressure_hpa = '$file_pressure +_hpa', pressure_tendency = '$file_pressur +e_tendency', weather_type = '$file_weather_ +type'"; my $mo_raw = $dbh->do($mo_raw_sql, undef) or die "Could not Insert record into met_office_ra +w_data \n";
The fields that are undefined are being written as 0.00, 0 or " " not NULL. I found an unclear reference where I thought the ..., undef) parameter on the $dbh->do would map the undef variables to NULL in MySQL but this appears to make no difference. I've read bits on data binding for this but not sure how I can apply it to my code. Hopefully I'm missing something simple - very grateful for any assistance - Thanks

In reply to Writing NULL values to a MySQL record via DBI by ureco

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.