say deadlock

andy.sh on 2009-07-14T10:40:29

Imagine you have to teach a bit of Perl. The first thing you'd probably say is "say". Yes, I hope you'd prefer to use 5.10 for teaching and at the first lesson wouldn't mention that there exist another 5x version which is not fully compatible with 5.10.

You can start teaching from print "Hello\n", having to explain the meaning of slash-n only, but it is rather boring to use "print" when you have working "say". But to run a programme with "say" you have to either use version or feature pragma, or use Modern::Perl. These are much more things to explain now.

Thus if you would like to demonstrate the brilliant short name "say", you have to bring with it odd and long instructions just to turn "say" on.


Two alternatives

moritz on 2009-07-14T19:51:56

perl6 -e 'say "Hello, World"'
perl -E 'say "Hello, World"'

OK, beat me for it ;-)

(I know that -E is not great because then you have to explain why it's available in the one-liner, and not in "normal" programs by default).

Re:Two alternatives

andy.sh on 2009-07-14T20:18:45

I thought about that during the day. These examples are good, and in fact I think that they may be used as the first examples of Perl code.

They slightly break the idea of showing pure Perl code, but it is better in that you don't need even a file to save the programme in. Just run it from the command line.

thirt alternative

jozef on 2009-07-15T18:21:51

perl -Mcommon::sense -le 'say "hi andy!"' # credits for digging out this module goes to daxim :)

sink or swim

slanning on 2009-07-15T22:29:21

Why not go the other way and do a hello world with as many builtins as possible. ^.^