For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > August 2005 > ref / hash problem









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author ref / hash problem
Brent Clark

2005-08-02, 4:59 pm

Hi list

I have my data as so (Thanks to Data::Dumper)

'Grac01' => {
'StndRm' => 'Standard Room',
'Suite' => 'Suite',
'Pent' => 'Penthouse'
},

My code is as so.

foreach my $roomCode ( keys %{ $ref_hash->{$fileName} }){ # This works
100%

foreach be( keys %{ $ref_hash->{$fileName}->{$roomCode} } ){ # Not working
print "Ok HERE IT IS $_ <br />\n";
}


I cant seem to get my second foreach to display the data of

Standard Room, or Suite etc.

If anyone would be kind to help me, it would be most appreciated.

Kind Regards
Brent Clark
John Doe

2005-08-02, 4:59 pm

Brent Clark am Montag, 1. August 2005 16.42:
> Hi list
>
> I have my data as so (Thanks to Data::Dumper)
>
> 'Grac01' => {
> 'StndRm' => 'Standard Room',
> 'Suite' => 'Suite',
> 'Pent' => 'Penthouse'
> },
>
> My code is as so.
>
> foreach my $roomCode ( keys %{ $ref_hash->{$fileName} }){ # This works
> 100%
>
> foreach be( keys %{ $ref_hash->{$fileName}->{$roomCode} } ){ # Not


What if you omit the "be"?
(do you write "use strict; use warnings" at the top of your script?)

> working print "Ok HERE IT IS $_ <br />\n";


($_ then would contain the key; to get the value, you would use

$ref_hash->{$fileName}->{$roomCode}->{$_};

in the print statement.
)


joe

> }
>
>
> I cant seem to get my second foreach to display the data of
>
> Standard Room, or Suite etc.
>
> If anyone would be kind to help me, it would be most appreciated.
>
> Kind Regards
> Brent Clark

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com