in reply to How to handle passed data in subroutines
Try my first piece of demo. It prints "abc", not "ABC", because the return from uc() is simply discarded, and the value of $str is not changed at all. That's exactly what was missed from your understandng.
use strict; my $str = "abc"; uc($str); print $str;
The second demo gives you "ABC", not "abc", because we assigned the result returned from uc(), which is "ABC", back to $str:
use strict; my $str = "abc"; $str = uc($str); print $str;
BTW, you normally should pass array ref, not array, to your subs, for performance reason. Also, if you pass multiple arrays, or array mixed with other stuffs, you can easily lose track of the boundary of your array.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: How to handle passed data in subroutines
by tilly (Archbishop) on Nov 20, 2003 at 05:30 UTC |