Re: How to get the Class name of an element

2010-04-17 Thread Kevin Ryde
Dave Hayes writes: > > if (ref($text) eq 'Gtk2::Entry') { I expect isa() is friendlier to subclasses, though wouldn't matter within a self-contained spot of code as such. A bit of a grep shows eq instead of isa in a few modules in cpan. I see with some embarrassment one of mine too! :-) Mayb

Re: How to get the Class name of an element

2010-04-16 Thread Dave Hayes
Pelle Nilsson writes: > if (substr($text, 0, 11) eq 'Gtk2::Entry') { > print "Entry!\n"; > } elsif (substr($text, 0, 14) eq 'Gtk2::ComboBox') { > print "ComboBox!\n"; > } This might be better written as if (ref($text) eq 'Gtk2::Entry') { ... :) -- Dave Hayes - Consultant - Altad

Re: How to get the Class name of an element

2010-04-16 Thread Aristotle Pagaltzis
* Pelle Nilsson [2010-04-16 13:00]: > If an object is used in a string context it will return > something like > > Gtk2::Entry=HASH(0x12cfba8) > > so you can use something like > > if (substr($text, 0, 11) eq 'Gtk2::Entry') { > print "Entry!\n"; > } elsif (substr($text, 0, 14) eq 'Gtk2::ComboB

Re: How to get the Class name of an element

2010-04-16 Thread Emmanuele Bassi
On Fri, 2010-04-16 at 12:59 +0200, Pelle Nilsson wrote: > If an object is used in a string context it will return something like > > Gtk2::Entry=HASH(0x12cfba8) > > so you can use something like > > if (substr($text, 0, 11) eq 'Gtk2::Entry') { > print "Entry!\n"; > } elsif (substr($text, 0,

Re: How to get the Class name of an element

2010-04-16 Thread Emmanuele Bassi
On Fri, 2010-04-16 at 09:25 +, l...@guenther-sohler.net wrote: > Its really a stupid question. this is not good OOP. if you feel the need to do a type check then you're probably doing the wrong thing. > If I write > > $text=Gtk2::Entry->new; > or > $text=Gtk2::ComboBoxEntry->new; > > how c

Re: How to get the Class name of an element

2010-04-16 Thread Pelle Nilsson
If an object is used in a string context it will return something like Gtk2::Entry=HASH(0x12cfba8) so you can use something like if (substr($text, 0, 11) eq 'Gtk2::Entry') { print "Entry!\n"; } elsif (substr($text, 0, 14) eq 'Gtk2::ComboBox') { print "ComboBox!\n"; } /Pelle (sorry fo

How to get the Class name of an element

2010-04-16 Thread list
Its really a stupid question. If I write $text=Gtk2::Entry->new; or $text=Gtk2::ComboBoxEntry->new; how can I check later in the program if $text is an Entry or an ComboBoxEntry ? if($text->get_text != undef) { } does not help. It already tries to call an undefined function rds ___