On Mon, Jun 27, 2005 at 10:52:24AM -0400, Sam Tregar wrote:
> On Mon, 27 Jun 2005, Tim Bunce wrote:
>
> > Did my one-liner not work?
> >
> > @$ch = grep { $_ } @$ch if @$ch % 120 == 0 && @$ch;
> >
> > It's much smaller/faster/simpler.
>
> Like I said in the comment, the easy way with grep undoes weaken().
Ah, sorry. Not paying enough attention.
> After that line the references are no longer weak-refs and never
> become undef. That said, my solution is gross... There's probably a
> middle ground that's simpler and still works!
Try this:
if (@$ch % 120 == 0 && @$ch) {
@$ch = grep { $_ } @$ch;
Scalar::Util::weaken($_) for @$ch;
}
> > Could also include a recursive version (untested):
> >
> > sub show_child_handles {
> > my ($h, $level) = @_;
> > foreach my $ch (grep { defined } @{$h->{ChildHandles}}) {
> > printf "%sh %s %s\n", $ch->{Type}, ("\t" x $level||=0), $ch;
> > show_child_handles($ch, $level+1);
> > }
> > }
>
> Sure. I'm curious - is there ever a fourth level?
There are vague references in the code to the idea of 'field buffer'
handles but basically, no.
Thanks Sam.
Tim.