Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Index or iterate - your choice

by jdporter (Paladin)
on Jan 27, 2021 at 14:29 UTC ( [id://11127519]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11127519]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-19 00:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found