Re: Gtk2::TreeModel - foreach





Use pass a hash or other reference to the foreach():

Martin, very cool!  I sure have a long way to go before I can even imagine a solution like this.


Or here is an alternative that doesn't use the foreach method.


sub search {
    my ($model, $search_string) = @_;
    my $iter  = $model->iter_first;
    my $found;

    do {
      if ($model->get($iter, 0) ~= /$search_string/) {
         $found = 1;
      } else {
         $iter  = $model->iter_next;
      }
    } while (! $found && $iter);

    return $found;
}


if ( search($model, 'bob') ) {
    print ("Welcome back!\n");
} else {
   print ("Who are you!\n");
}

Jeff, thank you for keeping it simple and offering an alternative.

You guys make it look so easy.

ZM.


      __________________________________________________________________________________
Win 1 of 4 Sony home entertainment packs thanks to Yahoo!7.
Enter now: http://au.docs.yahoo.com/homepageset/




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]