I tried using use diagnostics but the line it gave was the $sth->execute which is referenced at find (\&wanted, $dir); but I'm fairly sure the error is in my trying to call $db_id as when I tried $db_id=$dbh->last_insert_id($catalog, $schema, $table, $field) it returned Mo&72sEbUI-0@foo.bar.com and the 0 was repeated after the - for all the emails. I'd be grateful for some advice on sorting this script out. Thanks.use strict; use warnings; use File::Find; use DBI; my $admin = 'admin'; my $dbh = DBI->connect("dbi:mysql:list:localhost", "user", "pword") or + die "Connection Error: $DBI::errstr\n";; my $sthcheck; my $sthcaluser; my $sth; my $sthuser; my ($email, $password, $caluser, $opt_out, $founduser); my $dir = "file"; find (\&wanted, $dir); sub wanted { my @useroutput; open (IN, "$_") or die "Can't open $_"; @useroutput = <IN>; close(IN); chomp @useroutput; foreach my $person (@useroutput) { my ($email, $password) = split(/:/, $person); #need to check if user email exists. If not then add if (!defined $sthcheck) { $sthcheck = $dbh->prepare_cached("SELECT name FROM user WHERE + name = ?") or die "Couldn't prepare statement: " . $dbh->errstr; } $sthcheck->execute($email); ($founduser) = $sthcheck->fetchrow_array(); next $person unless !$founduser; if ($password eq "no_password" ) { $password =~ s/no_password//; } #get the last id my $db_id = $sth->{'mysql_insertid'}; if (!$db_id) { $db_id = 0; } my $caluser = create_random() . "-" . $db_id . "\@foo.bar.com"; my $opt_out="F"; if (!defined $sth) { $sth = $dbh->prepare_cached("INSERT INTO user(name, pass, cal_nam +e, opt_out) VALUES (?,?,?,?)") or die "Couldn't prepare statement: " +. $dbh->errstr; } $sth->execute($email, $password, $caluser, $opt_out); #insert user role into db my $sthadmin = $dbh->prepare ("INSERT INTO user_role(name, role) + VALUES (?,\"admin\")") or die "Couldn't prepare statement: " . $dbh- +>errstr; if (!defined $sthuser) { $sthuser = $dbh->prepare_cached("INSERT INTO user_role(name, role +) VALUES (?,\"user\")") or die "Couldn't prepare statement: " . $dbh- +>errstr; } #if section to place helpline as the site admin if (grep $email eq $_, $admin ) { $sthadmin->execute($email); } else { $sthuser->execute($email); } } } sub create_random { my @chars = ( "A" .. "Z", "a" .. "z", 0 .. 9, qw(! @ $ % ^ & *) ); my $user_name = join("", @chars[ map { rand @chars } ( 1 .. 10 ) ]) +; return $user_name; } $sth->finish(); $dbh->disconnect();
In reply to Trying to create a fake address through random numbers and a looping issue by Quicksilver
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |