Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-26 00:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found