in reply to Re^2: Six uses for curlies?
in thread Six uses for curlies?

This is an excellent thread for folks new to Perl like me. Perhaps moving this thread to the Tutorials section would be appropriate.
I have been wondering about significant examples of operator overloading within Perl and this is a good one.
Perhaps a reason for the need for operator overloading is due to the finite number of symbols on a standard keyboard?
To me having an operator with six or seven different meanings could lend to confusion, but perhaps the burden of concocting different operators for each of the seven meanings is too great.
I haven't finished reading Wall et al's "Programming Perl" so I don't know what the creator's philosophy is in this regard.

Edited by planetscape - removed small tags

Replies are listed 'Best First'.
Re^4: Six uses for curlies?
by dimar (Curate) on Jan 13, 2006 at 17:59 UTC
    Perhaps a reason for the need for operator overloading is due to the finite number of symbols on a standard keyboard?

    Not necessarily, when you consider that any arbitrary language construct can be represented with any arbitrary arrangement of symbols, for example:

    MY_NAMED_BLOCK: BlockBegin ### No curly braces were used, but then this is just ### pseudocode, not perl. For (0..10): print sys.accumulator; print sys.newline; EndFor BlockEnd

    If you wanted to, you could easily write a script to convert that into perl. Is it perl? No, but it can be translated unambiguously.

    When I was new to programming, I used to be much more impressed with the fancy symbols, and I thought there had to be some esoteric and mathematically precise rationale for every element of syntax. Perhaps (on some very deep epistemological level) there is. Another explanation, however, is that some things are just plain easier to type, and different people have different preferences, backgrounds, expectations and styles.

    This is an important consideration, because it will help you to be less intimidated about learning new things in perl (and even learning new languages); and less mystified by conventions that may seem confusing at first, but end up saving you a *lot* of time and hassle when you understand what they are good for.


    =oQDlNWYsBHI5JXZ2VGIulGIlJXYgQkUPxEIlhGdgY2bgMXZ5VGIlhGV
Re^4: Six uses for curlies?
by Anonymous Monk on Jan 17, 2006 at 17:19 UTC
    Are {} "operators"? I don't think of them as such.

    To me, most of the aforementioned uses are conceptually the same. Braces surround something and return its result. Syntactically there is some difference, eg if ${foo}_bar really acted like a block then the foo would be a bare word, but conceptually if you think of braces as a block which is strongly bound to whatever is to the left of the opening brace, I don't think you'll go far wrong.