Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Does perl sub using stack and possible to crash?

by Corion (Pope)
on Jan 17, 2013 at 10:13 UTC ( #1013744=note: print w/ replies, xml ) Need Help??


in reply to Does perl sub using stack and possible to crash?

Global variables are global, and @_ are aliases. This is easily replicated and tested with the following code (your while loop will never terminate so I used a for loop instead):

#!perl -w use strict; use Data::Dumper; my @someNameArray = qw(foo bar baz); print Dumper \@someNameArray; for(@someNameArray){ print( "Before: $_\n" );# $_ correct frobnicate($_); print( "After : $_\n" );# $_ changed } print "Final:\n"; print Dumper \@someNameArray; sub frobnicate { $_[0] = "changed value from '$_[0]'"; }; __END__ $VAR1 = [ 'foo', 'bar', 'baz' ]; Before: foo After : changed value from 'foo' Before: bar After : changed value from 'bar' Before: baz After : changed value from 'baz' Final: $VAR1 = [ 'changed value from \'foo\'', 'changed value from \'bar\'', 'changed value from \'baz\'' ];

If you

I suggest to use a lexical iterator instead of $_, and don't have your callees change elements in @_. Using a lexical iterator prevents action at a distance from called subroutines. Using @_ will need more changes and information about $finder->isExist(...).


Comment on Re: Does perl sub using stack and possible to crash?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2015-07-28 01:58 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 (251 votes), past polls