Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8040925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:03:14+00:00 2026-06-05T04:03:14+00:00

I am using a DB::CDBI class for accessing the database in our application. Our

  • 0

I am using a DB::CDBI class for accessing the database in our application. Our project is in object-oriented Perl.

package LT::LanguageImport;
use strict;
use warnings;
use base 'Misk5::CDBI';

__PACKAGE__->table( 'english_text_translation' );
__PACKAGE__->columns( Primary => qw/english language translation/ );
__PACKAGE__->columns( Essential => qw/english language translation/ );
__PACKAGE__->has_a( english => 'LT::EnglishLanguage' );

In one such scenario, I am supposed to check if a row in a table exists. I am using the built-in search API in a CDBI call.

sub find_translation {
    my $translation_exists_r_not = $class->search(
        english     => $english,
        language    => $language,
        translation => $translation
    );
    return;
}

$translation_exists_r_not is getting the expected values depending on the inputs given in the search. If the row exists, then the _data is updated with the row details.

$translation_exists_r_not = bless({
        '_data' => [
            {
                'language'    => 'polish',
                'translation' => 'Admin',
                'english'     => 'admin'
            }
        ],
        '_place'  => 0,
        '_mapper' => [],
        '_class'  => 'LT::LanguageImport'
    },
    'Class::DBI::Iterator'
);

If the row desn’t exist, then I get a return value like this.

$translation_exists_r_not = bless({
        '_data'   => [],
        '_place'  => 0,
        '_mapper' => [],
        '_class'  => 'LT::LanguageImport'
    },
    'Class::DBI::Iterator'
);

I want to return the value of translation from this sub find_translation depending on the search result. I am not able to get a best condition for this.

I tried copying the _data into an array, but I’m not sure how to proceed further. As _data will be an empty arrayref and another condition it will have a hashref inside the arrayref.

my @Arr = $translation_exists_r_not->{'_data'};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T04:03:15+00:00Added an answer on June 5, 2026 at 4:03 am

    CDBI’s search method will return an iterator, because there may be multiple rows returned depending on your criteria.

    If you know there can be only one row that matches your criteria, you want to use the retrieve method, i.e.:

    if (my $translation_exists_r_not = $class->retrieve(
        english     => $english,
        language    => $language,
        translation => $translation
    )){
        return [$translation_exists_r_not->translation,
                'Misk5::TranslationAlreadyExists']
    }
    else {
        return [ '', undef ]
    }
    

    And if multiple rows can be returned from your search, and you’re only interested in the truthiness, then again, don’t be rummaging around inside the CDBI::Iterator, but use its methods:

    my $translation_exists_r_not = $class->search(
        english     => $english,
        language    => $language,
        translation => $translation
    ); # returns an iterator
    if ($translation_exists_r_not){
        my $first = $translation_exists_r_not->first;
        return [ $first->translation, 'Misk5::TranslationAlreadyExists' ]
    }
    

    Have a look at perldoc Class::DBI and perldoc Class::DBI::Iterator. CDBI has excellent documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the navigator.geolocation object in JavaScript. Trying to establish accurate ranges, but wondering exactly
Using Android TelephonyManager an application can obtain the state of data activity over the
Using emacs on Ubuntu 11.10. I want to connect to a SQL Server database
Using EF Code First I have an model object that has multiple properties that
Using Rails 3 and ActiveModel, I am unable to use the self. syntax to
Using boost python I need create nested namespace. Assume I have following cpp class
Using JQuery, how do I select all elements with class x within an element
(Using WPF) In a small application that I wrote, I am using some count-down
Using LINQ on collections, what is the difference between the following lines of code?
using (var file_stream = File.Create(users.xml)) { var serializer = new XmlSerializer(typeof(PasswordManager)); serializer.Serialize(file_stream, this); file_stream.Close();

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.