Re: problems when prepending elements to a clist



On Tue, 2002-05-07 at 13:16, Kim Schulz wrote:
hi
I have the following code:

 sub parse_xml{
   open(RDF, 'slashdot.rdf');
   my $content = do{local $/; <RDF>};;
   my(%result, @tmp);
   parseXML(\%result, \$content);
   foreach my $item (@{$result{'items'}}) {
     print ($item->{'title'});
     push @tmp, [ $item->{'title'} => $item->{'link'}];
   }
   $clist->prepend(@tmp);
 }


but in my clist I only get gibberish like ARRAY(0x81ab5b8).
what do I do wrong? I can print the $item->{title} and {link} without
problems. 

-- 
Kim Schulz - Freelance Development    | There's one fool at least in
www.schulz.dk  - En nørds bekendelser | every married couple. 
www.linuxia.dk - hverdagens små hacks | 

I assume your Gtk::CList has two columns (title and link).

The problem is this line

 push @tmp, [ $item->{'title'} => $item->{'link'}];

What you are doing here is creating an arrayref with the [] operator and
pushing it onto the array @tmp.  None of that is needed.  You can update
the Gtk::CList inside of your loop like this

sub parse_xml{
        open(RDF, 'slashdot.rdf');
        my $content = do{local $/; <RDF>};;
        my %result;
        parseXML(\%result, \$content);
        foreach my $item (@{$result{'items'}}) {
                print ($item->{'title'});
                #don't change the users view
                $clist->freeze;
                #add this row, personally I prefer append, but it 
                #doesn't matter
                $clist->prepend($item->{'title'}, $item->{'link'});
                #let the user scroll again
                $clist->thaw;
                #keep the GUI alive
                Gtk->main_iteration while (Gtk->events_pending);
        }
}


-- 
Today is Boomtime the 54th day of Discord in the YOLD 3168
Kallisti!

Missile Address: 33:48:3.521N  84:23:34.786W




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