Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^3: Returning Array

by MidLifeXis (Monsignor)
on Jun 27, 2012 at 14:23 UTC ( #978678=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Returning Array
in thread Returning Array

Replace the return with a function (push, unshift, splice, as examples) that builds up a temporary array that you return.

I would probably build it in two parts -- one that iterates over all of @data, one line at a time, and the other part that handles one line at a time. I might even put the part that iterates over @data back into the code that is calling your sub (perhaps with map or something similar).

Your code is basically selecting a group of lines, and then transforming them. To me that says something along these lines (see grep and map):

my @output = map { doTransformation( $_ ); } grep { shouldSelectData( $_ ); } @data;

--MidLifeXis


Comment on Re^3: Returning Array
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2015-07-01 23:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (24 votes), past polls