Hello monks, I have written a module inserter.pm which inserts a data stored in hash in to database.The module works works in such a way that there is a separate subroutine for each table.I wants to insert value in table named user_scenario.In which two fields are there i.e. name & description.In the case when there is no description exist I want nothing to insert in to it.

The corresponding subroutine is as follows:

Input:user_scenario_name,Us_result_type,description

sub _get_user_scenario { my ($self, $schema, $user_scenario) = @_; my $user_scenario_rs = undef; if(! ($user_scenario->{description} eq 'Not_exposed')) { eval { #get the number of user scenarios in the database table my $count = $schema->resultset("UserScenario")->count(); #insert user scenario, or if already in database, update the d +escription $user_scenario_rs = $schema->resultset("UserScenario")->update_or_create( { name => $user_scenario->{name}, description => $user_scenario->{description}, }, { key => "u_user_scenario_name" }, ) || die "Unable to update/insert data to table UserScenar +io: $!\n"; }; } else { // I don't wants to insert the empty description and I don't wants to + update the database for Not_exposed type of user scenario...So what +I supposed to do here? // } if($@) { #warn(); $self->log_writer()->write_error_row("Unable to get/insert dat +a to table UserScenario: $@"); return undef; } else { return $user_scenario_rs; } }

IF anybody knows how not to write in the database for a particular value then kindly let me know how to achieve this...Because I don't wants to update_or_create function to work on the database where description is Null or empty value.


In reply to A question on DBIx and inserting vales in Database by siddheshsawant

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.