Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Re: Learning Perl as a First (programming) language

by talexb (Canon)
on Aug 02, 2002 at 13:54 UTC ( #187088=note: print w/ replies, xml ) Need Help??


in reply to Re: Learning Perl as a First (programming) language
in thread Learning Perl as a First (programming) language

Since you asked, here's the equivalent in C (for those that aren't familiar -- I'm sure you are):

#include <stdio.h> int main(void) { int i; for ( i = 0; i < 10; i++ ) { printf ( "%d", i ); } }
The equivalent in Perl is
for ( $i = 0; $i < 10; $i++ ) { print $i; }
No variable declarations, a friendlier print statement, and no mysterious 'cargo-cult' include thingy.

Don't get me wrong -- I have programmed in C since the early 80's and I love the language. But Perl takes care of lots of the underlying stuff (how many times did I write fopen(), fread() and fclose() statements I wonder). That's why I think Perl is a better choice than C.

Perl can be a heavyweight language, but it can also be lightweight. To use the car analogy, C is a bit like the British Triumph, a little finicky, but piles of power and cornering. Pascal is a bit like a Pinto or a CV5 stuck in second gear. Perl is like a Porsche or a Lexus, nimble yet powerful.

--t. alex

"Mud, mud, glorious mud. Nothing quite like it for cooling the blood!"
--Michael Flanders and Donald Swann


Comment on Re: Re: Learning Perl as a First (programming) language
Select or Download Code
Re: Learning Perl as a First (programming) language
by Abigail-II (Bishop) on Aug 02, 2002 at 14:10 UTC
    Well, you are forgetting a my $i if you want to have equivalent code. I maintain the code is nearly identical - there's a few lines more in C, which look a lot for such a short program, but it wasn't linear in the size of the Perl program. Had you have had 100 of such loops, you'd have had the same amount of extra lines.

    I never claimed that C would have been a better choice than Perl. Instead, I said that I didn't consider C a good first language either. IMO there's only one reason to learn C before learning Perl and that's because there's so much of C in Perl. It makes you a better Perl programmer.

    Abigail

        Well, you are forgetting a my $i if you want to have equivalent code.
      No, :) I purposefully left it out, in order to demonstrate the point that Perl will autovivify a variable for you, while C will just throw an error. I also purposefully did not use strict or include the she-bang line.

      --t. alex

      "Mud, mud, glorious mud. Nothing quite like it for cooling the blood!"
      --Michael Flanders and Donald Swann

Re: Re: Re: Learning Perl as a First (programming) language
by sauoq (Abbot) on Aug 02, 2002 at 19:31 UTC
    Perl is like a Porsche or a Lexus, nimble yet powerful.

    I rather think Perl is more like a little Z3 that'll turn into a cement mixer, eigtheen wheeler, station wagon (complete with wood panel sides), tow truck, fire engine, or lear jet with the push of a button.

    Ok. . . with the push of many buttons in exactly the right order. . . or close to the right order anyway.

    -sauoq
    "My two cents aren't worth a dime.";
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://187088]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2015-07-07 02:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (86 votes), past polls