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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:44:42+00:00 2026-05-30T01:44:42+00:00

I am relatively new to Perl.I have been trying to insert data to database

  • 0

I am relatively new to Perl.I have been trying to insert data to database from a text file using a CGI script.I have written code for it and it’s working properly.but when i try to impose a limit on the data that is inserted using LIMIT keyword there is a problem.Please check where i am going wrong and what needs to be amended.Thanks for your advice.

here is the code

#!/usr/bin/perl

use warnings;
use strict;
use CGI ':standard';
use DBI;

if(param())
{
my @params=param();
my $limit=param('limit')||'';


my $dbh =DBI->connect("DBI:mysql:sample","root","");
my $var="LOAD DATA LOCAL INFILE 'C:/test.txt' INTO TABLE sample2 FIELDS TERMINATED       BY '\n' WHERE LIMIT 0,$limit";
my $sth = $dbh->do($var) or die "prepare failed: " . $dbh->errstr();
print $sth ."Records inserted";

$sth->finish();
$dbh->disconnect();

print
header(),
start_html(
-title=>'Welcome',
-text=>'#520063'
),
#h1("Records have been displayed"),
end_html();

}

else
{
print
header(),
start_html('A Simple Form'),
h1('Please enter the limit '),
start_form(),
'Limit: ',
textfield(-name=>'limit'),
br(),
#'Phone Number: ',
#textfield(-name => 'number'),
#br(),
submit(),
end_form(),
end_html();
} 
  • 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-05-30T01:44:43+00:00Added an answer on May 30, 2026 at 1:44 am

    Without an error message I can’t be totally sure, but the problem is likely in your SQL.

    LOAD DATA LOCAL INFILE 'C:/test.txt'
    INTO TABLE sample2
    FIELDS TERMINATED BY '\n'
    WHERE LIMIT 0,$limit
    

    There’s problems.

    • There WHERE clause is empty (LIMIT is not part of the WHERE clause)
    • LOAD DATA INFILE does not take a WHERE clause
    • LOAD DATA INFILE does not take a LIMIT clause

    Basically that whole last line won’t work. In general, if a SQL command doesn’t work in a program try firing up the MySQL command line and debug the command there.

    LOAD DATA INFILE does not have a way to limit how many lines it will pull in, this is an oft requested feature. To work around it I would suggest copying and truncating the file before feeding it to MySQL.

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

Sidebar

Related Questions

I'm relatively new to Perl, writing some XML parsing scripts. I have done two
I am relatively new to rails and have been working my way through the
Relatively new to rails and trying to model a very simple family tree with
I'm relatively new to Nant, what i'd like to do is have a task
I'm relatively new to Mercurial and my team is trying it out right now
Im relatively new to PHP but have realized it is a powerfull tool. So
I am relatively new to the whole .NET thing, coming from a VB classic
Relatively new to dealing with XML in jQuery. I am trying to retrieve a
Relatively new to mySQL so this is probably an easy one: I have a
Being relatively new to the software industry I have come across a question of

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.