On Wed, Sep 02, 2009 at 01:46:39PM +0100, Lyle wrote:
> Line endings
>
> So that long lines of code can be easily broken over several lines, or
> short lines of code can be put on the same line, lines of Perl code must
> end with a semi colon ';'. As with comments there are of course exceptions.
That would mean that if I write this:
print "Hello World";
like this:
print
"Hello World";
it shouldn't work, as lines need to end with a semi-colon and there
should be one after the print.
Better to rephrase it as *statements* must end with a semi-colon.
> Variables
>
> ...
>
> Luckily Perl's variables aren't as strictly typed.
> Scalars
> In Perl integers, strings, etc, do not have to be defined separately and
> are more simply defined as Scalars e.g.
>
> $number = 10;
> $char = 'c';
> $huge = 'pages of information';
Worth pointing out that a scalar is a variable that can hold a single
value.
> It's good practice to have all or most your variables as local variables.
Why? </devils advocate>
Also, say lexical or scoped, not local. local means something subtlely
different in perl (see the local keyword).
> Scalars that have been initialized but not assigned a value have a
> special value known as NULL. Perl calls NULL undef, for undefined. undef
> is not the same as an empty string.
Instead of confusing them by talking about NULL and then say that perl
calls NULL undef, just talk about undef. You can talk about NULL later
if you have a chapter on databases.
> ? The 'our' syntax for defining global variables was introduced with
> Perl v5.6. Some people still prefer the old method of declaring globals
> with: use vars qw( $LIST @OF %GLOBALS );
You only need to declare them if you use strict. If you don't use
strict, then anything that isn't lexical is assumed to be global.
A good way to show why they should always use strict and warnings is,
once you've shown them subroutines, write some nice buggy code where
subroutines accidentally trample on each others' variables, and to
try to append an undef variable to a string.
> my $div = 5 / 5; # $div contains 1
May be worth mentioning operator precedence (eg 1+2*3 == 7, not 9), and
if people have a C-ish background point out how cool it is to not have
to cast between float and int.
--
David Cantrell | Minister for Arbitrary Justice
Deck of Cards: $1.29.
"101 Solitaire Variations" book: $6.59.
Cheap replacement for the one thing Windows is good at: priceless
-- Shane Lazarus
_______________________________________________
BristolBathPM mailing list
[email protected]
http://mailman.bristolbath.org/mailman/listinfo/bristolbathpm