in reply to Re^3: Parsing hash from XML::Simple
in thread Parsing hash from XML::Simple

I know, but it will be multiple cities. And using this I am still geting the same error
Can't use string ("visibility") as a HASH ref while "strict refs" in use at...
with:
foreach my $vals (%{$xml}) { print $vals->{city}{name}, "\n"; }
When you say "does not make sense" do you mean it will also not run?/code foreach my $vals (%{$xml}) { print $vals-

Replies are listed 'Best First'.
Re^5: Parsing hash from XML::Simple
by Corion (Patriarch) on May 16, 2016 at 19:47 UTC

    Please note that NetWallah suggested

    foreach my $vals (values %{ $xml }) {

    and not what you wrote:

    foreach my $vals (%{$xml}) {

    The two are distinctly different.

Re^5: Parsing hash from XML::Simple
by Laurent_R (Canon) on May 16, 2016 at 20:43 UTC
    When you say "does not make sense" do you mean it will also not run?/
    The data structure you posted contains only one hashref (with substructures). It does not make sense to run a foreach loop on that hashref, since you can access the data by direct dereferencing.

    We can only assume that this hashref is part of a bigger structure on which you would want to loop, but you don't show the larger structure, so that we can only make guesses.