> > >-----Original Message----- >From: Martin Schlemmer [mailto:martin.schlem...@nwu.ac.za] >Sent: Friday, November 20, 2009 6:48 AM >To: gtk-perl-list@gnome.org; Martin Schlemmer; Jeff Hallock; Zettai Muri >Subject: Re: Gtk2::TreeModel - foreach > >>>> On 2009/11/20 at 11:41 AM, Zettai Muri <zettaim...@ymail.com> wrote: >> I was just wondering, is there a return value of some sort or a way to >> get the return TRUE from the search sub, so that it is possible to then >> do something like: >> >> if ( $model->foreach(\&search, 'Bob') ) >> { >> print ("Welcome back!\n"); >> } >> else >> { >> print ("Who are you?\n"); >> } >> >> I have tried the above but my output is always: >> FOUND >> Who are you? >> > >Use pass a hash or other reference to the foreach(): >
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"); } _______________________________________________ gtk-perl-list mailing list gtk-perl-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-perl-list