For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > June 2007 > Re: the Database is not updated









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: the Database is not updated
Aruna Goke

2007-06-20, 9:59 pm

Chas Owens wrote:
> On 6/20/07, Paul Lalli <mritty@gmail.com> wrote:
> snip
> snip
>
> The rollback and commit methods will only have an effect if you have
> set AutoCommit => 0 in the hash you call the connect method with.
> Otherwise you will get a "commit ineffective with AutoCommit" or
> "rollback ineffective with AutoCommit" warning.
>

thank you all,

However, it was not updated bcos the acctuniqueid value was getting a
leading space which after i changed my code to read

$x[6]=~s/\s//gm;

the space was subtituted and all contents where updated.

Thank you.

Goksie

open FH, '<', $fn or die "The File $fn Could not be opened: $! \n";
while(<FH> )
{
#split the file into variables
@x[0,1,2,3,4,5,6]=split/,/;
$x[6]=~s/\s//gm;
$sth->execute($x[2], $x[5], $x[4], $x[6]) or die "Error executing
<<$sth->{Statement}>> with values @x[2,5,4,6]: $DBI::errstr";
}
Dr.Ruud

2007-06-21, 9:58 pm

Aruna Goke schreef:


Missing:

#!/usr/bin/perl
use strict;
use warnings;


> open FH, '<', $fn or die "The File $fn Could not be opened: $! \n";
> while(<FH> )
> {
> #split the file into variables


It is not about the file but about the (or each) row.
Maybe something more like:

# each row contains comma separated values, split them up into an
array

> @x[0,1,2,3,4,5,6]=split/,/;


There are several ways to rewrite this. I think I would go for:

my @x = (split /,/)[0..6];

or if I would know that after element 6 there are not multi-megabytes of
data:

my @x = split /,/, $_, 8; # put the remainder in $x[7]

or even just

my @x = split /,/;

> $x[6]=~s/\s//gm;
> $sth->execute($x[2], $x[5], $x[4], $x[6]) or die "Error executing
> <<$sth->{Statement}>> with values @x[2,5,4,6]: $DBI::errstr";
> }


That needs reformatting, to make your code easier to read. Whitespace is
cheap.

$x[6] = ~s/^[[:blank:]]+//; # ltrim

$sth->execute( @x[ 2, 5, 4, 6 ] )
or die "Error executing <<$sth->{Statement}>>"
. " with values '@x[2, 5, 4, 6]': $DBI::errstr";
}

--
Affijn, Ruud

"Gewoon is een tijger."

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com