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


In reply to RE: My life as a monk, day 1. by jbert
in thread My life as a monk, day 1. by Bowie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.