On Friday, June 25, 2004, at 11:33 AM, Wiggins d Anconia wrote:
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') {

Thank you! I'm using a very dated version of a Perl handbook which made no reference (no pun intended) to that at all!



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.

Yes, that was a slice. I forgot to fix the print statement, but the following if() had the correct use of $$ vs. @$. Whoops!


my @ar = @{ $foo1->[1] };

So, to be sure I am reading this correctly: {$foo1->[1]} dereferences the value at position 1 of $foo1, and the preceding @ treats the dereference as an array? Does this mean that the following line:


        if ($foo1->[0] eq 'yes') {

could also have been

        if (${$foo1->[0]} eq "yes") {

..?  If you do not specify a variable type, does it default to a string?

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.

Yes, this I figured out. I was experimenting earlier and found that $foo2[0][0] would work, but not $foo2[0]. I just couldn't get past the "first" dereference.


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,....

Yes.. A lot of my stuff is hardcoded right now, but using lists of lists makes things a lot easier (especially since sublists do not have to be the same size! Thank you Perl!). I'll check ou the perldoc's you listed.


Cheers,
Patrick


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to