troubleshooting Question

Converting to DBI database

Avatar of jedistar
jedistarFlag for Singapore asked on
5 Comments1 Solution213 ViewsLast Modified:

I'm currently using open/close to access/modify my data.csv:

Contents of data.csv:
# OS   | Q1  | Q2  | Q3  | Q4  |
redhat |8|10|5|9|6|1|4|3|2|7|6|7|6
novell |3|6|7|3|8|4|0|5|3|9|4|6|2

How do i convert my below codes to DBI, I need some knowledge on
how to use/manipulate DBI to access my data.csv and modify the contents.

Please help, thanks!

My codes:
$product = param("product");
my $ans1 = param("answerone");
my $ans2 = param("answertwo");
my $ans3 = param("answerthree");
my $ans4 = param("answerfour");

# Reading from CSV File
my $file = "../../data/data.csv";
open(FILE, "+<$file") || die "can't open $file: $!";
flock(FILE, LOCK_EX);

my @contents = <FILE>;
if ($product eq "windows") { $i = 1; };
if ($product eq "redhat")  { $i = 2; };
if ($product eq "solaris") { $i = 3; };
if ($product eq "novell")  { $i = 4; };

# Increment Survey Answers value
chomp $contents[$i];
my @temprow = split(/\|/, $contents[$i]);
$contents[$i] = join("|", @temprow)."\n";

seek FILE,0,0;

# Writing to CSV File
print FILE @contents;
close(FILE) || die "can't close $file: $!";
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros