Hi David,

On Wed, Mar 28, 2012 at 4:36 PM, Kronheim, David (Contr) <
david.kronh...@ftr.com> wrote:

> timothy adigun [2teezp...@gmail.com] wrote:
> >#!/usr/bin/perl
> >use warnings;
> >use strict;
> >
> >my @wanted   = qw( dad mum children);
> >my @children = qw(tim dan mercy);
> >my $ref      = {
> >    dad      => "mick",
> >    mum      => "eliz",
> >    children => { first => 'tim', second => 'dan', third => 'mercy', },
> >};
> >
> >foreach my $cell (@wanted) {
> >    print STDOUT "$cell:";
> >    if ( defined keys %{$ref} ) {
> >        print STDOUT $ref->{$cell}, "\n" if !ref( $ref->{$cell} );
> >        if ( ref( $ref->{$cell} ) ) {
> >            foreach my $child ( keys %{ $ref->{$cell} } ) {
> Tim: How is it the first time the print below produces: children:tim
> and the 2nd time just prints dan for $ref->{$cell}{$child}
> when it looks like all that happened is the value of $child changed from
> 'first' to 'second' ?
>

      Really, all that happened was a change of value, that is from 'tim'
to 'dan', etc for $ref->{$cell}{$child}. "children" however, is one of the
keys for the hash which includes dad and mum. If you put a "\n" in **print
STDOUT "$cell:";  i.e **print STDOUT "$cell:\n"; you will see that clearly!


> >                print STDOUT $ref->{$cell}{$child}, "\n\t";
> >            }
> >        }
> >    }
> >}
> >
> >*OUTPUT*
> >
> >dad:mick
> >mum:eliz
> >children:tim
> >            dan
> >            mercy
> >
> Thanks, David
>
> This communication is confidential.  Frontier only sends and receives
> email on the basis of the terms set out at
> http://www.frontier.com/email_disclaimer.
>



-- 
Tim

Reply via email to