|
Posted by Tad J McClellan on May 24, 2008, 11:15 am
Please log in for more thread options
[ There is no C/C++ in this sub-question.
Newsgroups: modified.
]
> #!/usr/bin/perl -w
#!/usr/bin/perl
use warnings;
use strict;
> # global array definition
> my @array = ("a","b","c");
>
> sub print_array {
my @array = @_; # a different array, named the same as the 1st (outer) one
> foreach my $element (@array) {
> $element .= "9";
> print $element . "\n";
> }
>
> }
>
> for ($i = 0; $i < 3; $i++) {
> &print_array();
print_array(@array);
> }
>
> How would I prevent $elment from modifying @array?
See above.
See also:
perldoc -q "difference between calling"
"Coping with Scoping":
http://perl.plover.com/FAQs/Namespaces.html
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher0cmdat/"
|