Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
×
Perl Programming

Apocalypse 3 151

rob_99 writes: "The third installment of the Apocalypse is out!" You may have missed the first or second Apocalypses. This one is roughly "all about operators".
This discussion has been archived. No new comments can be posted.

Apocalypse 3

Comments Filter:
  • by seanadams.com ( 463190 ) on Wednesday October 03, 2001 @06:20PM (#2385960) Homepage
    He stresses the importance of good huffman coding, then goes on to change the string concatenation operator "." to a three character sequence " _ "

    ...instead of:

    $a . $b . $c

    you'll say:

    $a _ $b _ $c


    String concatenation is such a commonly used perl feature that it deserves a single character operator. Discriminating between operators by the existence of white space before/after the character is an incredibly ugly kludge. Larry seems to admit it, too: This is to be construed as a feature

    At least we don't have to use "+", like in JavaScript!
  • by Mr_Huber ( 160160 ) on Wednesday October 03, 2001 @08:25PM (#2386420) Homepage
    Why, then, does Perl include a 'foreach' operator when a 'for' loop will do just fine? Efficiency. By giving the language a hint as to what you are going to do, it can iterate through the list faster and with fewer resources. I expect that when the implementation arrives, we will find the hyper operators offer a not-insignificant efficiency gain over a simple for loop.


    The point of Perl is not necessarily to provide more than one way to do things, but to make certain types of programming much easier than with other languages. There are things I do in Perl in an hour that would be a week undertaking in C or C++. If enough users are calling for these seemingly esoteric features, add them. The more expressive the language, the more useful.

  • by Anonymous Coward on Wednesday October 03, 2001 @10:03PM (#2386673)
    For all of those people who want to jump ship from perl6, all I can say is I'd give it some time. I've been playing around with the syntax in perl6, and I think people are giving it way too much short shrift, without thinking no less. Here, for example, are a couple of equivalent programs in perl6 and perl5:

    Concatenating two arrays together:

    perl5

    my $biggest_index = (@array1 > @array2)? @array1:
    @array2;

    for ($index = 0; $index $biggest_index; $index++)
    {
    $array1[$index] += $array2[$index];
    }

    perl6:

    @array1 ^+= @array2;

    Comparing all of the elements in an array to one another for equality:

    perl5:

    for ($xx = 0; $xx @array1; $xx++)
    {
    ($notequal = 1, last) if ($array1[$xx] ne $array2[$xx]);
    }
    if (@array1 != @array2)
    {
    $notequal = 1;
    }
    else
    {
    $notequal = 0;
    }

    Perl6:

    $notequal = (@array1 ^!= @array2);

    Perl5: setting an element to the first defined item:

    my $element = (defined($a))? $a : (defined($b))? $b: 'default';

    perl6:

    my $element = $a // $b // 'default';

    etc, etc. I could go on, but I'll leave it to damien && his exegesis...

    Now, you could argue that things like the above don't belong in the language proper, and that it would be better to write functions to do them, but believe me, there are a hell of a lot of different low level functions that you can write, all with a little wrinkle here or there that makes them *slightly* different from the functions that you've written before - like doing cmp instead of ==, and so on.

    So don't bolt before you see the final result.. I think its going to be really cool, especially being built on top of parrot....

    Ed

    (ps - as for the OO, I'd *also* hold my tongue if I were you. I've used the OO features of perl5 extensively, and its exceedingly flexible. There are aspects that I don't like (like no type checking of attributes as they are in a hash) but even this can be used to your advantage in programming.

    so its definitely *not* worthless, and definitely something worth checking into. 50,000 line APIs don't just spring up overnight...
  • Re:Change is good (Score:3, Insightful)

    by hillct ( 230132 ) on Thursday October 04, 2001 @12:45AM (#2387079) Homepage Journal
    In responding to the previous poster my first inclination was to defend my perl programming prowess but instead of descending into such a ridiculous debate of an issue that would only be of interest to my clients and myself, I'll just clarify my point which was more that I have never found anything that I wasn't able to do in perl more easily than I could have done in C and that I wasn't able to find any specific single item in Larry's article that would make my use of perl significantly more convenient or effective. That's not to say that I'm against making changes to perl. If it can be improved, so much the better.

    --CTH

Life is a whim of several billion cells to be you for a while.

Working...