Model->foreach and adding

Hi
I am trying to use model->foreach to replace the following piece of code

my $rows = $model->iter_n_children;
my $iter = $model->get_iter_first;
my @arr2;
foreach my $c (0 .. $rows - 2) {
  push @arr2, $c;
  push @arr2, undef;
}

my $n = 0;
foreach my $c (@arr2) {
  if ($n % 2 == 1) {
    $model->insert($n)
  }
  $n++;
}

The idea is that for for every row , a new row get added (as a row seperator)

This is my initial attempt, which blows up, if I dont have the return 1, and if I do stops have way. Obviously the rows are being created and carrying on, rather than just the initial rows.

my $model = $view->get_model;
my $rows = $model->iter_n_children;
$model->foreach(sub {
  my ($model, $path, $iter) = @_;
  my $row = $path->to_string;
  $model->insert($row + 1);
  if ($row == $rows * 2) {
    return 1;
  }
  else {
    return 0;
  }
});

Is this idea feasible at all, or is it best to stick with my (admittedly kludgey) original which works

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.