http://qs321.pair.com?node_id=301261


in reply to C vs. Perl

Some criticism about your code is in order.

In Perl you would write like this

In Perl I would write a one-liner.

perl -ane '$items{$F[0]} = $F[1] ;END{print "apples cost $items{apple} +\n" if $items{apple}}' data
your code should be able to handle any number of items

But yours will only handle as may item that can fit into your system's memory. If I had really to handle "any number of items" I would use a DBMS. And still you fail to convince me that I couldn't do the same in C. With more lines of code, perhaps, but I can do it in any language I have used so far.

#here you can also get the name from the user and print the #price.

But let's assume that there is no "apples" in your input. You would print an empty price. You should check first.

The bottom line is, you don't compare two main languages using such a trivial example and offering no alternatives, especially if your "positive" example is questionable as well.

I have coded in C for many years, and when I switched to Perl it wasn't because C wasn't up to my expectations. It's simply that Perl is easier and faster to code.

If you want to consider a more critical comparison of a specific implementation of a well established algorithm, have a look at Perl's pearls

 _  _ _  _  
(_|| | |(_|><
 _|