Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: passing reference to subroutine

by asthaonard (Acolyte)
on Oct 28, 2011 at 09:17 UTC ( [id://934348]=note: print w/replies, xml ) Need Help??


in reply to Re: passing reference to subroutine
in thread passing reference to subroutine

it was just an example :) what I'm trying to do is modification of passed in array

thanks for help

Replies are listed 'Best First'.
Re^3: passing reference to subroutine
by wfsp (Abbot) on Oct 28, 2011 at 11:33 UTC
    modification of passed in array
    You may have good reasons to do that but when I'm faced with similar situations I wonder if returning a new version of the array might be better/safer.
    #! /usr/perl/bin use warnings; use strict; use Data::Dumper; sub process_array_ref { my $initial_array_ref = shift; my @processed_array; for my $element (@{$initial_array_ref}){ # do something with element # validate, normalise, error checking, # convert to metric, skip, whatever push @processed_array, sprintf(qq{processed: %s}, $element); } return \@processed_array; } my $initial_array_ref = ['a','b','c','d','e']; my $processed_array_ref = process_array_ref($initial_array_ref); print Dumper($processed_array_ref);
    I often find that debugging/maintainance is easier with this approach. YMMV.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-24 13:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found