I just ran across the following bit of code in pudge's journal on use Perl;

I just used "&&=" for the first time in real code. I hadn't planned on it, but there it was:

my($cfg1, $cfg2, $VirtualUser) = @_; $VirtualUser &&= getCurrentVirtualUser();
If the flag is true, then get the current value for the virtualuser. Cool. It is weird when you have been using perl for so long but use some feature for the first time.

So $VirtualUser changes it's meaning from 'do I want the virtual user' to 'the virtual user is'.

This caught my eye because I recently wrote a procedure in which a certain variable was first a string, then an array reference, and then a hash reference. While in this case the variable always signified the same thing (a header, FWIW) and so is 'monosignant' the type changed not once but twice ( polytypic? :), I thought perhaps I'd ask what other people think of these things.

Are your variables invariably monosignant and monotypic? Why or why not?

On one hand I don't see why they should be (mono-*) if the flow of the code suggests otherwise. On the other hand, I don't expect my variables to change type and so I may get quite confused when someone starts dereferencing what I was sure was a plain string. On the gripping hand, if I pay attention I should notice when said string becomes a hash ref, shouldn't I?

I just can't decide whether this is a Good Thing(tm) or not.

Scott

P.S. What do you think of 'polysignant'? Anyone got a better word for what I mean?


In reply to Polysignant variables by scott

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.