in reply to Re^4: Perl vs C
in thread Perl vs C

Yes, a char is a character. But char*, is a pointer to an character. And char** is a pointer to a pointer to a character (array).

Ok some examples:
in Perl:

#!usr/bin/perl -w use warnings; my @list = ("a1", "b23", "c45", "d1"); print join (" ",@list),"\n"; #prints: a1 b23 c45 d1
In Perl, the list "knows" how big it is.
This is not true in C! In C we have to do stuff to help things out! Like this:
include <stdio.h> int main () { char *list[] = {"a1", "b23", "c45", "d1",'\0'}; // list is an array of pointers to chars char **mover; for (mover=list; *mover ;mover++) printf ("%s ",*mover); printf("\n"); } // prints: a1 b23 c45 d1
For me, the difference is obvious! The Perl version is cool!
The alternative way in C would be to keep track of the number of items in the list array instead of a NULL value sentinel (and yes, there are more ways than than one I showed above). All ways are a pain in the rear compared with Perl!

Perl lists may be changed at will just like in C. I don't understand this comment: "lists are unmutable". Please explain, I just don't understand what you mean.

Replies are listed 'Best First'.
Re^6: Perl vs C
by JavaFan (Canon) on Mar 16, 2009 at 14:07 UTC
    I don't understand this comment: "lists are unmutable". Please explain, I just don't understand what you mean.
    Try to make pure Perl program that modifies a list. Come back when you either have such a program, or when you are convince this isn't possible.
      Here is a simple thing that removes things from a Perl list that do not match a criteria.
      #!usr/bin/perl -w use warnings; my @list = ("a1", "b23", "c45", "d1", "b43", "b65"); print join (" ",@list),"\n"; #prints: a1 b23 c45 d1 b43 b65 @list = grep{!/^b/}@list; #remove things that start with b print join (" ",@list),"\n"; #prints: a1 c45 d1
        Now you're modifying an array, swapping one value (a list) for another (another list). Calling the array @list doesn't change the fact it's an array. The code below doesn't modify '3' either - it just replaces the value of a variable.
        my $var = 3; $var++; say $var; # Prints 4.