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 8107853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:54:37+00:00 2026-06-06T00:54:37+00:00

Right now, I have a database with around 20 columns and 70 rows. I

  • 0

Right now, I have a database with around 20 columns and 70 rows. I want to iterate through each row and save each row as a separate data block, with the file name being generated by the first three columns. I already have SQL code selecting the specific columns I want and ordering it according to the parameters I want. The directory I want the files is in c:/database/first_past.

In my code, $ds is a variable that is an array of hashes, i.e. my current database. I have two for loops that iterate through the database and get down to the row, but I am unsure about the line to insert to save the row as its own separate file in the directory mentioned above with the specific title parameters.

Is this possible in Perl? Here is a portion of the code I am currently using:

for my $rec (@{$ds->{DATA}}) {
    for my $role (keys %{$rec} } {
        #here is the save file line? ("$role=$rec->{$role}"
    }
}

$ds is an array of hashes and the DATA field is all the data for one row.

  • 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-06T00:54:40+00:00Added an answer on June 6, 2026 at 12:54 am
    use DBI qw( );
    
    my $dbh = DBI->connect($dsn, $user, $passwd, {
       RaiseError       => 1,
       PrintError       => 0,
       PrintWarn        => 1,
       AutoCommit       => 1,
       FetchHashKeyName => 'NAME_lc',
    });
    
    my $sth = $dbh->prepare('
        SELECT *
          FROM Table
         ORDER BY ...
    ');
    
    $sth->execute();
    while (my $row = $sth->fetch()) {
        my $fn = join('-', @{$row}[0,1,2]);
        my $qfn = "c:\\database\\first_past\\" . $fn;
        open(my $fh, '>', $qfn) or die $!;
        print($fh ...);
    }
    

    DBI, open, print


    For your follow up question:

    $sth->execute();
    while (my $row = $sth->fetch()) {
        my $fn = join('-', @{$row}[0,1,2]);
        my $qfn = "c:\\database\\first_past\\" . $fn;
        open(my $fh, '>>', $qfn) or die $!;
        print($fh ...);
    }
    

    or

    my $last_fn;
    my $fh;
    $sth->execute();
    while (my $row = $sth->fetch()) {
        my $fn = join('-', @{$row}[0,1,2]);
        if (!defined($last_fn) || $last_fn ne $fn) {
            $last_fn = $fn;
            my $qfn = "c:\\database\\first_past\\" . $fn;
            open($fh, '>', $qfn) or die $!;
        }
    
        print($fh ...);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in my app i need to save some data. Right now i use CoreData,
I'm trying to create a faster query, right now i have large databases. My
Good day! I right now have a function the drags an element from a
Right now I have this SQL query which is valid but always times out:
Right now I have def min(array,starting,ending) minimum = starting for i in starting+1 ..ending
Right now I have double numba = 5212.6312 String.Format({0:C}, Convert.ToInt32(numba) ) This will give
Right now I have something like this in NHibernate: Expression.Like(property, value, MatchMode.Anywhere) and that
Right now we have AD/Exchange to manage all of our users logins/e-mail on-site at
Right now I have been trying to use Launchpad's API to write a small
Right now i have a line of code, in vb, that calls a text

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.