in reply to Index or iterate - your choice

It looks like GetSegments returns an array ref. If so, then SegmentCount is superfluous, no?

my $segments = $elfFile->GetSegments(); for my $segIndex (0 .. #$segments) { $segments->[$segIndex]->FileSize() or next; print $segments->[$segIndex]->Describe(head => 16, tail => 16, wid +th => 32) };
But even the index is unnecessary (unless you actually need the number for some reason):
print $_->Describe(head => 16, tail => 16, width => 32) for grep $_->FileSize, @$segments;

If GetSegments doesn't in fact return an array ref, then make a method that does. :-) It could even be a tied array for more perlishness.

Replies are listed 'Best First'.
Re^2: Index or iterate - your choice
by GrandFather (Saint) on Jan 27, 2021 at 21:14 UTC

    Actually GetSegments() was returning the internal ProgramHeader object which had an overload for @{}. But that was overthinking the plumbing so I've changed it to return a list.

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond