Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • if you also want to say something like:
    my $house = %house{87};
    when the data is stored in a hash?

    Here is why I ask...

    I also had the problem (at first) with the array slice. I thought initially that it was a sigil issue and an issue with semantics. (As you have explained)

    But, I noticed that I did not have the issue with a hash. It seemed to me that if the sigil was causing me to have a semantic problem that the problem would carry to other cases... but, in my case... it did not.

    So, I thought about it some more. Then, I realized that I didn't have the issue with the hash because I would get an immediate error if I tried to do it with the hash.

    But, I was NOT getting that kind of feedback with the array... because sometimes the thing "Just Works" like you want it to. Even tho you asked for something else... what you go was useful.

    So, the "problem" got reinforced.

    In the end, I solved it by thinking first about WHAT I wanted... I wanted a single scalar. Those are denoted by '$'. Next I think... OK, what is the name of the variable holding the data... then I'm done if the variable is in a scalar.

    Or, I mentally treat the [] and {} as sigils to indicate that the variable HOLDING the data is an array or a hash.

    (I'm sure someone is going to find a flaw in my thinking and really screw me up ;-))
    • That's an interesting point: the immediate punishment of mistakes fixes habits quicker than things seeming to work. I certainly have seen the mistake made more often with arrays than hashes.

      The warnings pragma catches this misuse nowadays, but many beginners either don't know about it or don't use it.

      Unfortunately, I didn't learn hashes until I had already familiarised myself with arrays, so I can't answer your first question.