Solved

perl insert to database

Posted on 2008-10-07
3
574 Views
Last Modified: 2012-05-05
I have two set of values
 ABCD|CDE|EDFF

1234|321|234|

I want to insert these values using Perl script to a table in Sybase something like this:

Name      Value
ABCD      1234
CDE      1234
EDFF      1234
CDE      321
CDE      321
CDE      321
EDFF      234
EDFF      234
EDFF      234

Please advise
0
Comment
Question by:saibsk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 39

Expert Comment

by:Adam314
ID: 22663572

#if $dbh is your database handle:
my $sth = $dbh->prepare('INSERT INTO table (Name, Value) VALUES (?, ?)')
  or die "Could not prepare: $DBI::errstr\n";
my $value1='ABCD|CDE|EDFF';
my $value2='1234|321|234';
 
for my $v2 (split/\|/, $value2) {
	for my $v1 (split/\|/, $value1) {
		$sth->execute($v1, $v2) or die "Could not execute: $DBI::errstr\n";
	}
}

Open in new window

0
 

Author Comment

by:saibsk
ID: 22663797
But I want o have a check on the value2 such that there whenever it is empyt i need to insert Null.
0
 
LVL 39

Accepted Solution

by:
Adam314 earned 500 total points
ID: 22666156
$sth->execute($v1, $v2 or undef) or die "Could not execute: $DBI::errstr\n";
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question