TonyShirt <> wrote:
> #I'm Trying to traverse an array slice that has been passed to a sub
No you're not. You are trying to traverse an LoL that is passed
via a reference to an array.
> #I'm not sure what perl is doing when I set the reference to @_
You do not set any reference to @_ ...
> $Slice[1]=["a","b","c"];
> $Slice[2]=["d","e","f"];
>
> printslice(\@Slice);
The arguments are not a slice. The argument is an array reference.
printslice( @Slice[1,2] );
_That_ would be passing an array slice.
> sub printslice{
> @tempslice = @_;
>
> foreach my $x (@tempslice){
> foreach ($w,$y,$z){
> print $w."\n";
I am at a complete loss as to what you think that inner foreach
is supposed to be doing. You are printing a variable that has
never been given any value...
> }
> }
> }
>
> #I would like the output to be the first value in the slice i.e.:
There are NO "slices" anywhere in the code you posted!
> #a
> #d
>
> #Could any one help?
We could if we knew what you wanted.
Here is my guess:
---------------------
sub printslice{
my($array_ref) = @_;
foreach my $inner_array (@$array_ref){
next unless defined $inner_array; # $Slice[0] is undef
print "$inner_array->[0]\n"; # print the first element
}
}
---------------------
--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas