The Perl Conference Salt Lake City 2018 Banner

Perl Style: Avoid Symbolic References

  • Beginners often think they want to have a variable contain the name of a variable.

        $fred    = 23;
        $varname = "fred";
        ++$varname;         # $fred now 24
    
  • This works sometimes, but is a bad idea. They only work on global variables. Global variables are bad because they can easily collide accidentally.

  • They do not work under the use strict pragma

  • They are not true references and consequently are not reference counted or garbage collected.

  • Use a hash or a real reference instead.


Forward to Using A Hash Instead of $$name
Back to Avoid Byte Processing
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