Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: can't use certain hashnames when traversing a slightly complex hash

by AnomalousMonk (Monsignor)
on Jan 06, 2013 at 15:41 UTC ( #1011893=note: print w/ replies, xml ) Need Help??


in reply to can't use certain hashnames when traversing a slightly complex hash

I get to the filename with this:

foreach my $g (@gists) { my @files = keys(%{$g->{files}}); my $file = $files[0]; # $file is now main.html ... }

One final note. The code quoted from the OP works as commented if and only if there is exactly one key in the  'files' sub-hash (and, of course, the name of the key is 'main.html'). If there are two or more keys, the 'order' of keys in the hash is not guaranteed whatsoever, so  'main.html' might be at index 0, index 1, ...


Comment on Re: can't use certain hashnames when traversing a slightly complex hash
Select or Download Code
Re^2: can't use certain hashnames when traversing a slightly complex hash
by gideondsouza (Pilgrim) on Jan 06, 2013 at 15:46 UTC

    Yep, it's all good. I simplified the code and the hash while posting.

    I'm always interested in the first entry of the files sub-hash. (The rest are forks of the original Github gist.)

    Thanks for looking out :)

      I'm always interested in the first entry of the files sub-hash.

      Hmmm...     Again, and just for the record, the  'files' sub-hash (or any hash) can be said to have a 'first' element if and only if it has exactly one element. The only true ordering in a hash (or associative array) is the association between key/value pairs.

        Ohh ..I understand what you mean now!!!

        Seems github doesn't mentioned specifically whether or files will contain one or more entries. I've emailed them to find out....

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1011893]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2014-09-03 03:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (35 votes), past polls