Мое подумать приводит к такому огромному коду))) а хотелось бы собрать со split
| Код | sub parse_categories {
my @arr = localtime(time); $arr[4]++; $arr[5] =~ s/1/20/; local $start_date = "$arr[3].$arr[4].$arr[5] $arr[2]:$arr[1]"; print "start parser_categories - $start_date\n"; local $dbh = DBI->connect("DBI:mysql:$mysqlbase;$mysqlserver","$mysqluser","$mysqlpassword",{PrintError => 0, RaiseError => 0}); &exec_command("set names utf8;");
my %ca = (); my $command = "select ind from myshop_categories;"; my $q = $dbh->prepare($command); $q->execute(); while (my $r = $q->fetchrow_arrayref) { $ca{$$r[0]} = "on"; } local $dbh = DBI->connect("DBI:mysql:$mysqlbase;$mysqlserver","$mysqluser","$mysqlpassword",{PrintError => 0, RaiseError => 0}); &exec_command("set names utf8;"); my ($buff,$command,$cur_id); my $all_count=0,$cont,$count; my $first = 1; my $tag = '<category '; my ($el,%cat,$usd); my $file = "test.xml"; if (!open (FILE, "$tmp_path/$file")) { print "error open file - $tmp_path/$file\n"; return; }
local $mail = ""; local ($new, $kolvo) = (0, 0); my $categories = ""; my @arr = split($tag,$buff); $cont=$tag.(pop @arr) if ($count == 10485760); my $first = 1; for (my $i=$first; $i<@arr; $i++) { $el = $tag.$arr[$i]; $el = encode("utf8", decode("utf8", $el)); $id = getAttribute('category','id',$el); $pid = getAttribute('category','parent_id',$el);
if (($empty_lines ne '')&&($empty_lines > 0)){ $empty_lines--; next if ($empty_lines > 0); }
$el =~ s/\\//g;
my $name = getBody('category',$el); next if ($category == 3811); if (($ca{$id} ne "") and ($ARGV[2] eq "update")) { print "upd $id;$pid;$name;\n"; &exec_command("update categories set name = \'$name\', pid = \'$pid\' where id = \'$id\';"); } next if ($ca{$id} ne ""); print "$id;$pid;$name;\n"; &exec_command("insert into categories (id, name, pid, kolvo) values (\'$id\', \'$name\', \'$pid\', 0);"); } &update_categories;
|
|