in reply to Re: Only using scalers and references
in thread Only using scalers and references

>> Hash values are scalars

yeah, thats what my understanding is and all the more reason to use references exclusively. cos (correct me if i'm wrong) references are the simplest way to get a hash of hashes

and (again correct me if i'm wrong) you can't pass a hash or array into a sub - it get 'flattened' into a scaler ... though if you pass a reference of a hash in there it survives perfectly intact

to me it seems like 'original 1987' perl is somewhat hampered and the the reference arrow (->) was created so that perl can do all the stuff that most modern languages do by default

  • Comment on Re^2: Only using scalers and references

Replies are listed 'Best First'.
Re^3: Only using scalers and references
by ikegami (Patriarch) on Sep 25, 2008 at 06:36 UTC

    the reference arrow (->) was created so that perl can do all the stuff that most modern languages do by default

    First, I think the ability to take references and to dereference them has existed for longer than the "reference arrow".

    Second, references have existed in Perl at least since 1994, before Java and JavaScript even existed.

    Finally, you seem to be confusing references (pointers on which arithmetic cannot be performed) and passing by reference (changing a parameter in a function changes it in the caller). Perl always passes by reference.

    that most modern languages do by default

    What "most modern languages" do is a bad thing. It's a compromise to increase program speed. Perl6 has many improvements in that area.


    The rest of this post is a getting off-topic. Just some nits.

Re^3: Only using scalers and references
by jwkrahn (Abbot) on Sep 25, 2008 at 06:12 UTC
    it get 'flattened' into a scaler ...

    No, it gets 'flattened' into a list.   See perlsub for details on what happens with subroutine arguments.

Re^3: Only using scalers and references
by jethro (Monsignor) on Sep 25, 2008 at 13:11 UTC

    Exactly. And the french language is hampered as well, with their subject before verb method of specifiying things ;-).

    Seriously, the use of the sigils in perl may be something that is controversial to newcomers (like the spaces-are-syntax feature of python) and there may be reasons that that approach is not the best, but you are looking at it with PHP eyes. And finding fault in places that are just unfamiliar to you

    I get the same feeling when I look at (((((lisp))))) and if I had to program in lisp today, it would probably be a perl program in lisps clothing. And the same phenomenon happens when c or pascal programmers had to adopt c++ years ago and really only programmed c or pascal in the new language.

    Using references exclusively because they are needed for a hash of hashes is like saying "I eat rice exclusively because without it you can't make nigiri sushi". Sounds like flame bait to me. Or do you really use only one data structure for all problems ?

    Naturally 1987 perl was hampered. It was one of the first of the fifth generation languages and had to invent many of the things the newer languages could later do from the start. If it hadn't evolved it would be history by now. For example object oriented features were build in so that perl could do stuff that most oo-languages do by default. The interesting thing is how seamlessly that was achieved in perl without breaking old stuff.