in reply to Re: Type checker not checking out
in thread Type checker not checking out
This doesn't work, because map_recursive will descend an extra level into the Foo structure itself, and give me intermingled 1s and 0s which have no meaning to me or my program whatsoever.package Foo; sub new { bless {}, shift } sub get { $_[0]->{$_[1]} } sub set { $_[0]->{$_[1]} = $_[2] } package main; my @list = (Foo->new, Foo->new, Foo->new); $list[0]->set('a', 'b'); $list[1]->set('b', 'a'); $list[2]->set('x', 'y'); my $isa_foo = sub { UNIVERSAL::isa(shift, 'Foo') }; print join ',', map_recursive(\@list, $isa_foo);
It descends into the Foo, finding it to be a hash, and declares 0 on 'a', 'b', and 'y', since they aren't Foos. Or:
And here I'm looking to check for an array of hashes. But oh my, 55 isn't a hash, so this gets disqualified. You see now why map_recursive won't do; the format I'm using allows one to specify the whole structure.my @list2 = ( {a => 'm'}, { 1 => 55}, { Foo => 'Bar' }); my $h = sub { UNIVERSAL::isa(shift, 'HASH') }; print join ',', map_recursive (\@list2, $h);
However, it doesn't quite work yet...
Update: clemburg's solution below works better than the one above. I think I'll probably use that. Thanks you, clemburg.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Type checker not checking out
by clemburg (Curate) on Aug 06, 2001 at 13:15 UTC |