Lasker has asked for the wisdom of the Perl Monks concerning the following question:

Hi there! I am working on a Gtk-Perl project, but I've just run into trouble. I have a CList and I want to set certain data on each of its rows, but I can't put this get_row_data() to work properly. Here's the code:

foreach (keys %{$dades->[0]}) { $feines[0] = $dades->[0]->{$_}->{'client_id'}; $feines[1] = $dades->[0]->{$_}->{'treb_id'}; $feines[2] = $dades->[0]->{$_}->{'zona_nom'}; $feines[3] = $dades->[0]->{$_}->{'feina_desc'}; $feines[4] = $dades->[0]->{$_}->{'feina_tipus'}; $feines[5] = $dades->[0]->{$_}->{'status'}; my $row = $form->{'feines'}->append(@feines); my $valor = $dades->[0]->{$_}->{'feina_id'}; my $tmp = $valor; # If I don't do this, then get_row_data returns an UNKNOWN ref + afterwards... weird $form->{'feines'}->set_row_data($row, $tmp); print "Fila $row, valor $tmp\n"; } [...] # $event contains the number of the CList row that has been selected, +let's say 1. $glob_rowid = $form->{'feines'}->get_row_data($event); print "Row $event; Data: $glob_rowid"; print Dumper $glob_rowid;

There. Now, let's have a look at STDOUT:

Fila 0, valor 2 Fila 1, valor 1 Fila 2, valor 3 Row 1; Data: SCALAR(0x8640110) $VAR1 = \undef;

Shouldn't this return $tmp? The fact that if I don't do $tmp = $valor gets me to an UNKNOWN ref looks a little bit strange to me... any ideas about *how* get_row_data and set_row_data should be used? (According to Stephen Wilhelm's tutorial, its use should be "self-explanatory"... oops ;P) Am I doing anything else wrong?

As always, any help will be greatly appreciated :)


$ touch tita
$ mv tita /dev/null
mv: cannot move `tita' to `/dev/null': Permission denied
... whoops ;P

Replies are listed 'Best First'.
Re: Gtk-Perl $CList-get_row_data() problems
by count0 (Friar) on Jan 08, 2002 at 03:48 UTC
    Without knowing what's in %dades, it's hard to say.. But here's a quick rundown on how to use set_row_data() and get_row_data().

    These two functions are provided as a way to attach arbitrary data to a CList row.
    Their basic use is:
    $clist_obj->set_row_data ($row_number, $data_reference); $data_reference = $clist_obj->get_row_data ($row_number);

    It's very important to note that the user data must be a reference. It can be any type of reference, hower.

    If this little tidbit doesn't help you fix the error, just post a reply with more of the surrounding code.

    On a somewhat side note, I realize parts of the Gtk+ and Gnome (and the Gdk, though this shouldn't be much needed) documents for the Perl bindings are rather unclear, or incomplete.... I'm currently (among other things) writing some extended docs. If you find any other parts that are unclear, or incomplete.. please let me know and I'll add that to my TO-DOC list ;)

    In the meantime, if you know C, don't hesitate to look at the tutorial and API documentation at Gtk.org (and at developer.gnome.org for the Gnome::* modules).

    Update: spelling fix: s/There/Their/

      Hey, you got it! Neither $tmp nor $valor were, of course, a reference (in fact, I insisted on evaluating and dereferencing $dades to get the scalar value... poor fool of me ;P). I did check the C Gtk manual, and saw that in C a pointer had to be passed to the function, but I simply ignored it.

      By set_row_data()ing the whole big arrayref $dades this stuff seems to work.

      while (1) { print "Many thanks dude! :-))"; }