I was surprised to see how much Perl looks and behaves to C. Today, I have mastered Hello World, the preverbial base on the mountain. Tomorrow, I ascend further into the realm of string manipulation and arrays.

Replies are listed 'Best First'.
RE: My life as a monk, day 1.
by jbert (Priest) on Apr 18, 2000 at 16:41 UTC
    Yes, perl borrows heavily from C, awk, bourne shell and other places.

    (Apparently the:

    print "Foo...\n" if $verbose;
    syntax is from a dialect of BASIC.

    The good thing about these similarities is that it encourages coders with some familiarity.

    The bad thing is that they might not realise that compared with the 'strand' of coding they are familiar with from before, the 'braid' which is perl often has better ways to do a given task.

    e.g. a C coder starting at perl might loop through an array like this:

    my @array = ( "foo", "bar", "baz" ); my $i; my $array_size = scalar( @array ); for( $i = 0; $i < $array_size; $i++ ) { ...do something with $array[$i]...including assigning to it }
    instead of:
    my @array = ( "foo", "bar", "baz" ); foreach my $value ( @array ) { ...do something with $value...including assigning to it }
    whereas a shell scripter would be more likely to have used the latter construct in the first place. And vice versa for other things.

    Lastly, top tip for every perl coder is *ALWAYS* use the '-w' switch. It basically stops you shooting yourself in the foot in many ways. (You can include it on the first line of your script:

    #!/usr/bin/perl -w ...your script here...
    and thanks to the magic of perl, this will work on windows as well as Unix.

    Even more lastly, and especially if you are coming from C, consider always putting:

    use strict;
    at the top of each script. If you don't perl won't warn you if you don't declare variables (and do other marginal stuff). If you don't declare variables, they are global by default. If that doesn't scare you, then well, happy debugging.

    And honestly, definitely lastly, try looking into CPAN (and/or the PPM modules if you use ActiveState perl on Win32). One of the key reasons to use perl is the useful amount of library code which is there to interface to practically everything and its toaster's pet dog.

    Good luck and have fun

RE: My life as a monk, day 1.
by Anonymous Monk on Apr 15, 2000 at 01:13 UTC
    Once a novice approached the master and said: - I think I understand the Perl-nature. It is like the C-nature, but w +ith built-in regexes and hashes. The master smiled and said: - For the Wolf to survive in the mountain, she must be able to fight. +For the Eagle to survive in the mountain, she must be able to fly. Fo +r the Salmon to survive in the mountain, she must be able to swim. Th +e Wolf, the Eagle, the Salmon; these are all good at what they do. However, there is another species which survives in the mountain: the +Man. The Man does not have a strong bite, or wings, or gills. Indeed, + the Man is poor at all of these things, and would lose in a fight ag +ainst the Wolf, or in a swim against the Salmon. However, the Man doe +s all those things, and therein lies its power - by doing all things, + and by knowing what to do, the Man not only survives in the mountain +, he also builds a monastery to teach his disciples to be like the Wo +lf, or the Hawk, or the Salmon. Perl is like the Man. It thrives where other languages perish, not by +being the best at any given thing, but by being able to do it all, an +d by knowing to take advantage of this ability. Like the Man, Perl is + a generalist. And so must be the Perl programmer, for the only way t +o achieve the Perl-nature is to become one with it.