Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

by AnomalousMonk (Canon)
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, ...

Replies are listed 'Best First'.
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?
[Corion]: hippo: Yes, but I'm not sure that it's even worth the effort of implementing it at all...
[Corion]: You'll only ever need that option if you have a long-running query whose results are not cached by your DB already, and in those cases I presume that the programmer will want to maintain the temporary tables themselves - I wouldn't know when to drop ...
[Corion]: ... the temporary tables, and also don't have a good idea on how to create unique table names for them
[hippo]: OIC. In that case leave it out but invite feature requests and see if any of the users suggest it. :-)
[Corion]: Talking about this makes me realize that it's likely only a half useful idea. But it still would be convenient to have as an option...
[Corion]: hippo: Hmmm - yeah, I could document it and wait for code implementing that option to show up ;-D

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (11)
As of 2017-02-23 15:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (347 votes). Check out past polls.