RE: Gtk2::TreeModel - foreach
- From: Jeff Hallock <Jhallock WBandA com>
- To: Martin Schlemmer <Martin Schlemmer nwu ac za>, "gtk-perl-list gnome org" <gtk-perl-list gnome org>, Zettai Muri <zettaimuri ymail com>
- Subject: RE: Gtk2::TreeModel - foreach
- Date: Fri, 20 Nov 2009 10:41:21 -0500
-----Original Message-----
From: Martin Schlemmer [mailto:Martin Schlemmer 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 <zettaimuri 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");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]