Hello Monks

I am working on Perl Database project and I am stuck at one problem. In my project I am using DBIx::Class to perform the database operations.But for the following function my script is getting aborted.The function causing problem is as follows:

sub _get_user_scenario { my ($self, $schema, $user_scenario) = @_; my $user_scenario_rs = undef; my $user_scenario_desc; # In the case where the description is not Null if($user_scenario->{description}){ $user_scenario_desc= $user_scenario->{description}; }else{ Line #799 ===> $user_scenario_desc = $schema->resultset("UserS +cenario")->search({ "name" =>$user_scenario->{name}, })->first->description; } 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_o +r_create( { name => $user_scenario->{name}, description => $user_scenario_desc, }, { key => "u_user_scenario_name" }, ) || die "Unable to update/insert data to table UserScena +rio: $!\n"; }; if($@){ #warn(); $self->log_writer()->write_error_row("Unable to get/insert da +ta to table UserScenario: $@"); return undef; }else{ $self->log_writer()->write_row("Inserted values into user_sce +nario table"); print"Inserted values into user_scenario table\n"; return $user_scenario_rs; } }

Here I am trying to insert some values into user_scenario table.Among those values I am trying to insert the value for description if it is already defined in the hash else I am trying to extract it's value using search function. But this case is not working for the user_scenarios whose description is not stored in the hash as well as not present in the database.I am getting an error like this for line # 799 is as follows(in the code line # is specified)

Can't call method "description" on an undefined value at DataLoader/Inserter.pm line 799.

Kindly help me out to deal with this DBIx error. Thanks in advance !!!!


In reply to A doubt about DBIx::Class 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.