John Doe wrote:
>
> Hello all,
Hello,
> i write script that open and read file but i have problem.
> First, here are a script:
> ----
> #!/usr/bin/perl
Change that to:
#!/usr/bin/perl -w
use strict;
> use DBI;
>
> my $dbuser = "xxx";
> my $dbpass = "xxx";
> my $db = "xxx";
>
> my $u_dbuser = "xxx";
> my $u_dbpass = "xxx";
> my $u_db = "xxx";
>
> my $sth = "";
> my $dbh = "";
> my $result = "";
> my $sql = "";
> my $tree = "/mnt/ftp/ftp1/users/";
> my $user = "";
> my $filequota = ".ftpquota"; # file contain record format 0 0
> my $temp = "";
>
> $sql = "SELECT username FROM tbl_users";
>
> $dbh = DBI->connect("DBI:mysql:$db", $dbuser, $dbpass) || die "MySQL is
> down\n";
> $sth = $dbh->prepare($sql);
> $sth->execute;
>
> $dbhnew = DBI->connect("DBI:mysql:$u_db", $u_dbuser, $u_dbpass) || die
> "MySQL is down\n";
> while(my @rows = $sth->fetchrow_array) {
> $user = $rows[0];
> $fulltree = $tree . $user . "/" . $filequota;
> $files = 0;
> $quotause = 0;
> if (-e $fulltree) { # check to see if file exist
> open(FILE, "$fulltree");
> my @f = <FILE>;
> close(FILE);
> $temp = $f[0];
> ($files, $quotause) = split(/ /,$temp); # line 39
> }
Change that if block to:
if ( open(FILE, $fulltree) and -s FILE ) {
local $_ = <FILE>;
close(FILE);
($files, $quotause) = split;
}
else {
warn "Cannot open $fulltree: $!";
next;
}
> $sqlnew = "UPDATE tbl_users SET files='$files', quotause='$quotause' WHERE
> username='$user'"; # line 41
> $sthnew = $dbhnew->prepare($sqlnew);
> $sthnew->execute;
> }
>
> $dbhnew->disconnect;
> $dbh->disconnect;
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>