[Tilesathome] Straw poll - use or/p "avoid duplicates" function?

Ævar Arnfjörð Bjarmason avarab at gmail.com
Sun Dec 21 18:58:01 GMT 2008


On Sun, Dec 21, 2008 at 4:03 PM, "Marc Schütz" <schuetzm at gmx.net> wrote:
> syntax error at orp-drawing.pm line 639, near "project["
> syntax error at orp-drawing.pm line 642, near "else"
> orp-drawing.pm had compilation errors.
>
> Maybe perl -c is more strict than the interpreter itself?

No, but whether something is a syntax error depends on the context in
which it was compiled.

  avar at aoeu:~$ perl -E 'project[]'
  syntax error at -e line 1, near "project["
  Execution of -e aborted due to compilation errors.
  avar at aoeu:~$ perl -E 'sub project {} project[]'
  avar at aoeu:~$

In this case orp-drawing.pm is required() by orp.pl which has defined
a `project' subroutine. And so `project[]' gets parsed as a call to
the `project' subroutine that takes an arrayref.

The compiler emits the error because when it encounters `foo[..]' it
has to decide whether it's a function call or whether someone's trying
to index an array referenced by a bareword. Perl still has a lot of
such legacy bareword cruft:

  avar at aoeu:~$ perl -E '*foo = [reverse 1..5]; say foo->[0]'
  5

  avar at aoeu:~$ perl -E 'say ENV->{SHELL}'
  /bin/bash

This should be fixed by changing the line to `project([ ... ])'. And
more generally by writing things as modules that aren't dependent on
previous compilation contexts.


More information about the Tilesathome mailing list