Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

perl insert to database

Posted on 2008-10-07
3
Medium Priority
?
582 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 2000 total points
ID: 22666156
$sth->execute($v1, $v2 or undef) or die "Could not execute: $DBI::errstr\n";
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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

609 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