On Monday 03 May 2010 15:08:34 Samuel Williams wrote:
> Dear Friends,
> 
> I'm looking for some help from the Perl community. I hope this is the right
> place to ask for information.

It may be, but you may also wish to ask on advoc...@perl.org

> 
> I'm putting together a website aimed at high school students and teachers,
> and would like to make sure the following page is as good as possible:
> 
>       http://programming.dojo.net.nz/languages/perl/index
> 
> In particular, "Why would I learn this language?" section needs to have a
> few paragraphs. I don't use Perl predominantly so I hoped that you could
> provide the main reasons why Perl is a language someone would want to
> learn about.

I've concentrated some answers to such questions about Perl advocacy on the 
Perl Beginners' Site:

* http://perl-begin.org/

* http://perl-begin.org/learn/#why-learn

> 
> It would also be great if someone could rewrite the Perl source code
> example so that it is as close as possible to the C implementation:
> 
>       http://programming.dojo.net.nz/languages/c/index
> 
> It should still use the Perl features where it makes sense. It would be
> great if you could include comments explaining how it works and what is
> happening (like the C example).

Here is my Perl version without comments:

[code]
#!/usr/bin/perl

use strict;
use warnings;

my $num_doors = 100;

my @is_open = ((0) x $num_doors);

for my $pass (0 .. ($num_doors-1))
{
    my $door = $pass;
    while ($door < $num_doors)
    {
        $is_open[$door] = !$is_open[$door];    
    }
    continue
    {
        $door += $pass+1;
    }
}

foreach my $door (0 .. $#is_open)
{
    printf("Door #%d is %s.\n",
        $door+1, ($is_open[$door] ? "open" : "closed")
    );
}
[/code]

Here it is with a few comments added:

[code]
#!/usr/bin/perl

use strict;
use warnings;

# Define the number of doors, to avoid magic numbers.
my $num_doors = 100;

# All the doors are closed by default.
my @is_open = ((0) x $num_doors);

# Loop over the passes of all the doors.
for my $pass (0 .. ($num_doors-1))
{
    my $door = $pass;
    # Loop over all the doors in the pass.
    while ($door < $num_doors)
    {
        # Flip the door's state.
        $is_open[$door] = !$is_open[$door];    
    }
    continue
    {
        # Advance the door number.
        $door += $pass+1;
    }
}

# Print the status of all the doors.
foreach my $door (0 .. $#is_open)
{
    printf("Door #%d is %s.\n",
        $door+1, ($is_open[$door] ? "open" : "closed")
    );
}

[/code]

Note that any moderately experienced Perl programmer will have no problem 
understanding the program without the comments, but I've included them here 
for people who are not familiar with Perl at all.

> 
> Any other suggestions or ideas for the Perl page would be fantastic, 

Well, it's not entirely accurate that Perl is "interpreted". As a matter of 
fact, its default implementation (called "perl5") is a P-code-based virtual 
machine that compiles the human-friendly Perl code into bytecode and then 
executes this bytecode. 

"including both lexical scope and dynamic scope." - while in Perl you can use 
lexical scoping for the "my" variables and dynamic scoping for the package-
scope variables ("use vars()" , "our", etc.), we still prefer to avoid using 
the dynamic scoping for package-scope variables as much as possible, and 
generally won't recommend it.

I would recommend you include a link to http://perl-begin.org/ on that page.

Saying that Perl supports both "imperative and function features" is a huge 
understatement of Perl's multi-paradigm capabilities that include many other 
paradigms - most of which are included on http://perl-begin.org/ in the 
various sections.

Hope it helps.

Regards,

        Shlomi Fish

> and
> any suggestions to other pages in general is also very helpful.
> 
>       http://programming.dojo.net.nz/
> 
> Kind regards,
> Samuel

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Interview with Ben Collins-Sussman - http://shlom.in/sussman

God considered inflicting XSLT as the tenth plague of Egypt, but then
decided against it because he thought it would be too evil.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to