Richard Heintze wrote: > Some help understanding this program would be greatly > appreciated! I'm really struggling with this perl > language! > Thanks, > siegfried > You should always use warnings and strict. In the first portion, you had a comma after the end of $x line and I believe you wanted ;. Now what you have created are referenced hashes and arrays. So the easiest way to access ( from my perspective is via -> operator. You should get some feedback and there will be numerous ways of doing what I have provided. But it is a start for you.
Wags ;) #!perl -w use strict; my $x= {'d' => 'y', 'f' => 'g'}; my $y = ['a', 'b', 'c', 'd']; # This works! Good! # What you are getting is the values, not the indexes of the refereneced array $y # 1. foreach my $i (@{$y}) { print "array i = $i\n" } # If you want the indexes, then here is one way: # 2. my $MyId = -1; while ( defined $y->[++$MyId] ) { printf "array i = %d\n", $MyId; } # (1) Why does not this work? How do I index an array? # (2) How do I compute the length of y instead of hard coding 3? # 3. for(my $i = 0; $i <= 3; $i++) { print "y[$i] = "[EMAIL PROTECTED]"\n"; } # You need to change as # 4. for(my $i = 0; $i < scalar(@{$y}); $i++) { print "y[$i] = ".$y->[$i]."\n"; } # $i receives the proper values # 5. foreach my $i (keys %{$x}) { # (4) Why does not this work? How do I index into my hash? print "hash i = $i => ".$x->{$i}."\n"; } Output: 1: array i = a array i = b array i = c array i = d 2. array i = 0 array i = 1 array i = 2 array i = 3 3. y[0] = a y[1] = b y[2] = c y[3] = d 4. y[0] = a y[1] = b y[2] = c y[3] = d 5. hash i = f => g hash i = d => y ********************************************************** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. **************************************************************** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]