Joseph Mwesigwa Bbaale wrote:
my @names = qw/ tom fred dan betty roy /;
my $result = &which_element_is("dan" @names);
sub which_element_is {
my($what, @array) = @_;
foreach (0..$#array) {
if ($what eq $array[$_]) {
return $_;
}
}
-1;
}
<snip>
Please, can someone help and explain to me how and why *...@array* is a copy of
*...@names?*
It's not, because the code you posted does not compile (missing comma
between the arguments to the which_element_is function).
You may think that I'm nitpicking, but it's important that code posted
here for review or comments does not include typos. Then the readers can
copy, paste and run the code, which makes it easier to provide
meaningful assistance.
In other words, next time, please copy and paste the code when preparing
a message with a question, do not retype it.
Another thing is that I was a little surprised to see that a book
written by Randal contains an example where a function is called with &
before the name. It's not just a matter of taste, but the & character
changes the behavior of the called function in some situations.
http://perldoc.perl.org/perlsub.html
There is no reason in this case to use the & character, and most Perl
programmers today would say that
which_element_is("dan", @names);
is the preferred 'normal' way to call a function.
(Others have answered the question you asked.)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/