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

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

In reply to Re: C vs. Perl by gmax
in thread C vs. Perl by podian

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.