Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: problems passing variables between subroutine

by philiprbrenan (Monk)
on Sep 04, 2012 at 19:34 UTC ( #991683=note: print w/ replies, xml ) Need Help??


in reply to problems passing variables between subroutines

Please use a reference an array rather than an actual array in:

sub create_output (\@$) { my (@array_of_lines, $entry_no_new) = @_;

as below:

use feature ":5.14"; use warnings FATAL => qw(all); use strict; use Data::Dump qw(dump pp); sub foo(\@) {my ($array) = @_; say "@$array"; } my @array = qw(1 2 3); foo(@array);

Produces

1 2 3


Comment on Re: problems passing variables between subroutine
Select or Download Code
Replies are listed 'Best First'.
Re^2: problems passing variables between subroutine
by GrandFather (Sage) on Sep 05, 2012 at 02:04 UTC

    Please don't encourage needless use of prototypes!

    Also in simple cases passing arrays by reference serves only to obscure the code so don't do that. Just because a technique fixes a problem in some cases, doesn't mean it should be used in all cases. Be selective about the habits you acquire and apply them along with a little consideration rather than blindly following a set of rules.

    True laziness is hard work

      Also in simple cases passing arrays by reference serves only to obscure the code so don't do that.

      Nonsense

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2015-07-08 00:32 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 (93 votes), past polls