> > As a perl novice, I'm unaware what I am doing wrong. Here's what I'm > working > with: > > use strict; > > my @newlist = ( > [ "yes", ['4', '5', '6'] ], > [ "no" ] > ); > > foreach my $foo1 (@newlist) {
Right here $foo1 contains an array reference. > print "[EMAIL PROTECTED]"; > if ($$foo1[0] eq "yes") { While you can dereference the array reference like you are doing, Perl allows a simpler syntax for readability when accessing into a reference, specifically the little arrow operator. So the above test can be written more simply as, if ($foo1->[0] eq 'yes') { > my @[EMAIL PROTECTED]; Right here I *believe* you are slicing into the dereferenced top level array, and returning the array reference in index 1 into the first element of @ar, but what you really want to be doing is dereferencing the array in index 1 into @ar, again the arrow operator can simplify this, though you will need to add a set of braces as well. my @ar = @{ $foo1->[1] }; Alternatively when you are more experienced you can skip this temporary variable completely, > foreach my $foo2 (@ar) { foreach my $foo2 (@{ $foo1->[1] }) { > print "foo2=$foo2\n"; > } > } > } > > If the first element of the first subarray is "yes", I want to process > the second element of the first subarray, which is an array itself > However, at the point where it says print "foo2=$foo2\n" I get > foo2=ARRAY(0xXXXXX). > if you see ARRAY(0x...) or HASH(0x...) that indicates a reference to that type of data structure, that you will then need to dereference. > My understanding of this is that $foo1 receives a reference to the > contents > of @newlist. Using `$$foo1[0] eq "yes"' treats the index at 0 of the > first > subarray as a string, where I can do the comparison. The line > `my @[EMAIL PROTECTED];' assigns the array at index 1 of foo1 to the array > @ar, > but I'm sure this is where I am going wrong. Close, see above. > > I've been tackling this for the past 48 hours, and am at a loss as to > what > to do. If anyone could point out what I'm doing wrong, it'd be greatly > appreciated! > Close, and keep at it. For some bedtime reading that will help with all of this you should check out, perldoc perldsc perldoc perllol perldoc perlreftut perldoc perlref Once you "get" references a whole other world will open up, good luck,.... http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>