------------------------------------------------ On Tue, 5 Aug 2003 12:03:34 -0400 , Smith Jeff D <[EMAIL PROTECTED]> wrote:
> Thanks for the response-I think that's got it. I must have tried everything > but the correct approach, which looks so obvious after the fact. > > One small question. In your sample code below, what format can I use to > refer to the individual members of the array referenced by $array in the > "each" loop? > > --I know that @$array will produce all members of the array within the > hash--how do I refer to the individual members of this array reference, > however big it might be--1 to whatever number of elements. In other words, > if @$array for server01 contains "SUCCESS Today's Date Other Details" and > "WARNING Today's date Other", how do I refer to array0 and array1 properly > in a loop so I can deal with each one separately---I know it isn't > @$array[0] and @array$[1] because of the errors I get, so it must be > something else, ->[0], ->[1] but see the following warning even though it > gives me a result (this is a loop following the grabbing of the $server and > $array in the while/each loop snippet you sent---- > > foreach my $i (@$array) { Right here you have alraedy stored the array reference to $array, so when you foreach over the array you are actually getting each element (detail line) into $i. So... > print "Detail: @$array->[$i]\n"; #Produces the following > warning: In the above you are trying to index into an array using the value from that array rather than an index. In other words what you are trying to retrieve is already in $i. If you want to access individual elements of the array by index you need to loop over an index range, not the array values themselves. For instance, foreach (0 .. @$array) { print $array->[$_]; } > Argument "SUCCESS06/01/2003What wasn't done > before\n" isn't numeric in array ele > ment at > C:\local\win32app\EventLog\EventDumperinPerl\ha.pl line 29, <DATA> line > 5. > Detail: WARNING06/01/2003Here are some details > Now the really cool thing is that you can remove (if you want) the temporary array dereference and access the elements directly, say you want the first element of the 'server1's log... $servers->{'server1'}->[0]; Or the first 5 elements of each of the servers... - Untested - foreach my $servername (keys (%$servers)) { my @first5lines = $servers->{$servername}->[0 .. 4]; } There are any number of ways to access into the data structure directly. Experience is about the only way to truly "get it" and once you do you won't lose it again, and the doors will seemingly flood open to its uses, and of course there is Perl OOP... http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]