Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: using 'keys' recursively on a hash of hashes

by krisahoch (Deacon)
on Aug 21, 2002 at 14:21 UTC ( [id://191743]=note: print w/replies, xml ) Need Help??


in reply to using 'keys' recursively on a hash of hashes

You may also want to think about misplaced commas and quotation marks. I have reformatted your hash to make it easier for me to read (sorry, I have single style dyslexia)


my %switch_hash =
(
 chrdex   => 
 {
  DEX   => 
  {
   '01-AUG-02'  => 1,
   '03-AUG-02'  => 3,#<-- Do you need this comma?
  }
 },
  
 uslcgb5e2sm => 
 {
  Greensboro  => 
  {
   '4-AUG-02'   => 1,
   '6-AUG-02'   => 2, #<-- Do you need this comma?
  }
 },
  
 uslecat25e1       => 
 {
  'Atlanta II' =>  #<-- Do you need quotation marks here?
  {
   '1-AUG-02'   => 1,
   '2-AUG-02'   => 3,
   '3-AUG-02'   => 1,
   '4-AUG-02'   => .25,  #<-- Do you need this comma?
  }
 }, #<-- Do you need this comma?
);

Kristofer

Microwaving a Twinkie is a bad idea <T.W.I.N.K.I.E.S Project>

  • Comment on Re: using 'keys' recursively on a hash of hashes

Replies are listed 'Best First'.
Re: Re: using 'keys' recursively on a hash of hashes
by Anonymous Monk on Aug 22, 2002 at 05:47 UTC
    The extraneous commas are no problem. That is one of the many improvements of Perl versus C. These extra commas allow easier additions to the hash with any of Emacs, Vi, Notepad, Wordpad, Ultra-edit, or even ed.

    Another possible style, which I prefer, consists in writing the comma at the beginning of the next line, not the end of the previous one. Example:

    my %switch_hash =
      (
       chrdex   => 
       {
        DEX   => 
        {
            '01-AUG-02'  => 1
          , '03-AUG-02'  => 3
        }
       }
        
     , uslcgb5e2sm => 
       {
        Greensboro  => 
        {
            '4-AUG-02'   => 1
          , '6-AUG-02'   => 2
        }
       },
        
     , uslecat25e1       => 
       {
        'Atlanta II' =>  # quotation marks are required here
        {
            '1-AUG-02'   => 1
          , '2-AUG-02'   => 3
          , '3-AUG-02'   => 1
          , '4-AUG-02'   => .25
        }
       }
      );
    
    
    This style also allows easier editing of the hash.
      Another possible style, which I prefer, consists in writing the comma at the beginning of the next line, not the end of the previous one.
      That reminds me of the professor who gave us our first programming classes back in university. He would write the semi-colons before the statements, not after them. (This was in Pascal, where semi-colons are statement separators, just like in Perl).
      This style also allows easier editing of the hash.
      Really? How? I see as disadvantage that if you remove the first item you need to modify the next line. Or if you insert an item at the beginning, you need to modify the next line too. The big advantage of putting a comma after the items is that you can always put a comma there, and don't have to do special things when adding or removing elements - not even at the beginning or end.

      Abigail

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-19 13:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found