I am kinda beginner in perl and I need know how can I check object class name.
My code is:
foreach my $y (keys %$x) {
print "$y\t$x->{$y}\n";
}
with output:
154176568 [object HTMLImageElement]
146292140 [object HTMLDocument]
153907016 [object HTMLImageElement]
I need to print just keys that are HTMLImageElement objects.
Now, question is:
(1) How can I check the class name
(2) How can I get/print class name
Looking at the source for JE, it looks like
JE::Object::Proxyis a subclass ofJE::Object, andJE::Objecthas a stringification method (use overload fallback => 1, ... '""' => 'to_string' ...).So when you do
print "$y\t$x->{$y}\n";, this is printing the result of stringifying$x->{$y}.You can stringify the object by putting it in double quotes, so
"$x->{$y}". This expression will then have values such as you saw being printed, e.g.'[object HTMLImageElement]'.If you want to pick up only HTMLImageElement objects, then you could check for these using an expression like
If you especially want to extract the string
'HTMLImageElement'from the stringified value, you could do that using a regexp, e.g.THOUGH, looking at the source for JE::Object::Proxy,
JE::Object::Proxyhas a methodclasswhich might perhaps return the name of the class that the object is a proxy for. So you might be able to get the class name using$x->{$y}->class, and then be able to test that directly as in$x->{$y}->class eq 'HTMLImageElement'.