What constitutes effective Perl training for non-P

2019-03-08 15:40发布

I've been working with Perl long enough that many of its idiosyncracies have become second nature to me. When new programmers join our group, they frequently have little to no experience with Perl, and it's usually my task to train them (to the extent necessary). I'd like to know what to focus on when training a programmer who is new to Perl but has experience with other languages (this question is meant to be language-agnostic, but most developers I've worked with have come from Java).

A few things occur to me:

  • The proper use of sigils
  • Referencing/Dereferencing
  • Use of list functions like map, grep, sort

Is there anything in particular that you've found it useful to focus on when helping a programmer to transition to Perl? Do you stress the similarities or the differences, or both in equal measure?

19条回答
淡お忘
2楼-- · 2019-03-08 15:50

as others said:

use strict;
use warnings;

maybe

use diagnostics;

for Java programmers:

use autodie; #or Fatal

English.pm
Moose/Mouse
Perl::Critic
perltidy

查看更多
Emotional °昔
3楼-- · 2019-03-08 15:51

Frankly, I'd just give them the Camel. It's such a readable and entertaining book, they'll be up and running in no time. I'm still laughing about 'Perl holds truth to be self-evident' and it must be ten years since I first read it.

查看更多
放荡不羁爱自由
4楼-- · 2019-03-08 15:53

Based on my experience in the workplace I'd recommend beginning with Perl's documentation (already covered here) and spend some time showing the student how to test code on the command line. It's really surprising how quickly someone can pick up a language when they can try something on the fly and make corrections until they get it right.

查看更多
时光不老,我们不散
5楼-- · 2019-03-08 15:54

Another surprising aspect is context. The fact that functions or even variables behave differently depending on whether they're referenced in list or scalar (or void) context has been an important detail for Perl trainees.

I usually insist on "higher-level" built in functions (map, grep, splice, split). Because of TMTOWTDI, many programmers only remember the more familiar aspects of Perl (like the C-style loops, substr and index) and use exclusively those.

After they are familiar with the language, Intermediate Perl and Advanced Perl Programming can give them further insights into the world of Perl

查看更多
该账号已被封号
6楼-- · 2019-03-08 15:54

Just joking, but whatever you do, show things like this LAST! ;)

use integer;@A=split//,<>;sub R{for$i(0..80){next if$A[$i];my%t=map{$_/9
==$i/9||$_%9==$i%9||$_/27==$i/27&&$_%9/3==$i%9/3?$A[$_]:0=>1}0..80;R($A[
$i]=$_)for grep{!$t{$_}}1..9;return$A[$i]=0}die@A}R
查看更多
ゆ 、 Hurt°
7楼-- · 2019-03-08 15:55

This is a single detail, not a full answer to your question, but for me, the mark of someone who's truly become oriented to Perl is someone who replaces this idiom:

for (my $i = 0; $i < @a; $i++)
{
  &do_something_with($array[$i]);
}

with this idiom:

foreach my $a (@array)
{
  &do_something_with($a);
}

Teach them lists as lists, not just as arrays. Teach the awesome data structures. Teach lists, hashes, lists of hashes, hashes of lists, hashes of hashes. That's where the biggest step up in power comes in over most conventional strongly-typed languages. (Ironically in the Java shop I joined this year, we sling around tons of arbitarily deep nested HashMap structures. Too many, in fact; I'm the one arguing for doing a bit less of it! But in Perl, this sort of thing is vital.)

查看更多
登录 后发表回答