#
# create an array
# note you can do the same stuff with hashes % and blobs *
#
@dog=('a','b','c');
#
# pass the array to function foo()
# note the \@ n \@dog passes it as a pointer
#
&foo(\@dog);
#
# all done - get outta here
#
exit;
sub foo {
#
# get the first argument which is a pointer to an array
#
my $name=@_[0];
#
# print the array - it should be a pointer
# or some such thing
#
print "my name=$name\n";
#
# use the pointer to the array
# note it is done with
# @$
#
foreach(@$name) {
print "$_\n";
}
$i=0;
#
# now use subscripts to walk thru the array
# again note the @$ in @$name
#
foreach(@$name) {
#
# note the $$ in $$name[$i]
#
print "$$name[$i]\n";
$i++;
}
#
# get the size of the array pointed to
# and walk thru the pointed array with
# a subscript.
# the size is
#
# $#$name
#
for($i=0;$i<=$#$name;$i++) {
#
# note the $$ in $$name[$i]
#
print "$$name[$i]\n";
}
#
# copy the array to a local array
# again note the @$ in @$name
#
my @frog=@$name;
foreach(@frog) {
print "$_\n";
}
#
# get outta here were are all done
#
return;
}