Richard Lee wrote:

say I have @data which below was pushed(bunch of them) with below hash of hash refernce

$VAR1 = {
         'element' => {
                                 'element2' => 'now',
                                 'element3' => '2',
                                 'element4' => 'serverxxx',
                               }
               };

and then I would call sub do_it like
do_it(somevalue, $data)

sub do_it {
my $something = shift;
    for (@_) {
      foreach my $XX ( keys %_ ) {
if ( exists ( $XX->{ element }{ element2 } ) && $XX->{ element }{ element4} eq "$something" ) { for my $key ( keys %{ $XX{ element } } ) { <------ Global symbol "%XX" requires explicit package name <--------------------?????
                print "$key\n";
                print "$XX and $XX{ element}{$key}\n";
           }
        }
       }
}

why does it not like XX in above line ??

Hmm. You're getting very confused here.

The answer to your question is that you're referencing $XX{element}
which would be an element of hash %XX which doesn't exist.

But your code is wrong on many levels:

- Use either 'for' or 'foreach' but not both for the same purpose

- You're iterating over @_, which now contains just $data since you
  shifted 'something' off it

- There is no hash %_

- $XX should really be $xx if not something descriptive

- You use both $XX->{element} and $XX{element}. Which is right?

- Don't quote "$something"

- If $XX is a hash reference, then printing is nonsensical

And finally, and most importantly, you don't post the code that gave you
the output you describe. As it stands it won't compile because the
subroutine call has a bareword parameter and there is a mismatch of
braces in the subroutine definition.

If you would like help then you're more than welcome, but at least
please give us a chance and don't make us try to work out what the
question is before we offer an answer.

Rob

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


Reply via email to