Perl Style: Using A Hash Instead of $$name

  • Using a variable to contain the name of another variable always suggests that perhaps someone doesn’t understand hashes very well. While you could write this:

        $name = "fred";
        $$name{WIFE} = "wilma";     # set %fred
    
        $name = "barney";           # set %barney
        $$name{WIFE} = "betty";
    

    Better to write:

        $folks{"fred"}  {WIFE} = "wilma";
        $folks{"barney"}{WIFE} = "betty";
    

Forward to Avoid Testing eof
Back to Avoid Symbolic References
Up to index

Copyright © 1998, Tom Christiansen All rights reserved.

Tags

Feedback

Something wrong with this article? Help us out by opening an issue or pull request on GitHub