Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

question on the "keys" builtin "function"

Status
Not open for further replies.

naq2

Programmer
Aug 3, 2004
74
FR
Can somebody tell me what is wrong with this code:
Code:
my @recognisedTags = keys %tmpTagGeneralLists ;
foreach my $i (@recognisedTags) {
   print $i ;
}

I'm expecting something like:
<a><b><br><hr>
but it cames with:
HASH(0x1a53a04)HASH(0x1a53a04)HASH(0x1a53a04)HASH(0x1a53a04)HASH(0x1a53a04)

Isn't key suppose to return the list of the keys? like a "string" array?

Thanks for you help.
 
How is %tmpTagGeneralLists getting built? It looks like your keys are hash refs.

 
Ok, just to be sure.

If I have pass an hash by reference, I do this to dereference it right?:
Code:
my %thisIsAnHash ;
mySub(\%thisIsAnHash) ;

sub mySub {
    my $rthisIsAnHash = $_[0] ;
    my %tmpHash = %$rthisIsAnHash ;
    # Now %tmpHash should be equal to %thisIsAnHash, right?
}

Am I doing right... I'm starting to have some doubts.
Thanks for your help.
 
As far as I understand, that's correct.
Again, how are the keys and values being put into your hash? I think that may be the cause of your problem.

 
Euh... I'm using the XML::Lite module.
But I test it (using Data::Dumper) before and after... and I have different values... I mean, I have values before but not after... I don't really understand this.

I'll let you know if I find a solution. Let me know if you have any ideas. Thanks.
 
Ok, I sorted it out. It was because I tried to pass by reference a value that was already a reference.

I was referencing a reference.

Thanks for your help.
 
OK, you're not being very clear. What do you mean you get different values 'before and after'? Before and after what? Also, post the actual code where you use XML::Lite to populate the hash.

 
naq,

Please answer the guy, it may help someone get where they're going quicker if they know a msitake was made b4, and you said you'd let us know

I'll let you know if I find a solution. Let me know if you have any ideas. Thanks.

--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Euh... ok... I'll do it... but tomorrow... coz it's already half two in Europe.

I think you'll understand. Thanks! :)
 
it's only 1:33 in Ireland

=)
Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
GRRR! You manage to be always right :)...
...I think I'll finish by posting it now!

Wait 5 more mins!
 
So, here we are! :)
Code:
use Data::Dumpter ;

$config = XMLin("./myBeautifulFile.xml") ;
print Dumper($config) ; #Hope for you that you don't have a big file!
beautifulSub(\%config) ;

sub beautifulSub {
    my $rtmpVar = $_[0] ;
    my %tmpVar = %$rtmpVar ;

    print Dumper($tmpVar) ;
    # won't work of course coz $config was already a reference to an hash
}

I think if I wanted this to work, I should use:
Code:
use Data::Dumpter ;

$config = XMLin("./myBeautifulFile.xml") ;
print Dumper($config) ; #Hope for you that you don't have a big file!
beautifulSub($config) ;

sub beautifulSub {
    my $rtmpVar = $_[0] ;
    
    print Dumper($rtmpVar) ;
}

or if you're mosochist:
Code:
use Data::Dumpter ;

$config = XMLin("./myBeautifulFile.xml") ;
print Dumper($config) ; #Hope for you that you don't have a big file!
beautifulSub(\$config) ;

sub beautifulSub {
    my $rrtmpVar = $_[0] ;
    my $rtmpVar = $$rrtmpVar ;
    
    print Dumper($rtmpVar) ;
}

...but it's too late for these kind of stuffs!
 
cheers
--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top