1. Coding effiency is about 5-10x. A well written Perl program will be far shorter than the equivalent thing in C. Sometimes stunningly so if you are on the right job for Perl. Execution effiency is maybe 1/3 or less than that of C, but often it is possible to implement a far more sophisticated algorithm in Perl that will make up a lot of that. There are an enourmous number of modules in the public domain that you can use! The mileage varies: some of these are really great, some are not so great. Also with Perl it is far easier to create complex dynamic data structures.
2. One fundamental roadblock to good Perl is mis-understanding of Perl lists and how to use them. A Perl list is not a C array! (An aside: One author says that the variable that defines a Perl list is an array, an array variable of a Perl list. I think that is confusing!). Don't equate Perl lists with C arrays! The sooner you get over that the better!
- There is no need for a "linked list" in Perl! A Perl list does what a C linked list can do and more! I guess one analogy could be that list oriented Perl functions operate on the C equivalent of linked lists. Say, you want to navigate a C linked list of something simple, a linked list of structs which have a simple int and a next pointer and remove all things in that list don't match some criteria for the number, In C this gets messy. In Perl, this is: @num_list=grep{$_ >2}@num_list;.
The Perl case of LoL (List of List) or LoH (List of Hash) is only very slightly more complex syntax.
In case of a "simple" C array,
if you want to "delete",item [3] in the array! How do you plan to "shrink" that
thing?
- A Perl list is even better than a C linked list because each individual thing in
a Perl list can be accessed,removed or added with an index. This feature is WAY over used by beginners.
But you can remove or add things the list via an index. A subscript like [2]is seldom
needed! Way cool!
So you should think of a Perl list more like a C linked list. It has those properties as well as C array properties.
3. Perl can have multiple lvalues! WOW!
This is a LISP like feature. This is VERY powerful when combined with the Perl idea
of a list "slice", like: my($city, $state) = (split(/\s+/,$line))[5,6];.
There are a bunch of complications in C with doing something like this. Here is one
line that makes it clear that I just need the 6th,7th thing on the space separated line!
All for now, I will think more about this.
In reply to Re: Perl vs C
by Marshall
in thread Perl vs C
by santhosh_89
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |