Skip to content

Instantly share code, notes, and snippets.

@gerdr
Created December 5, 2012 16:11
Show Gist options
  • Save gerdr/4216992 to your computer and use it in GitHub Desktop.
Save gerdr/4216992 to your computer and use it in GitHub Desktop.
auto-detecting Perl source files

Language dialect:

  • --perl as a catch-all
  • --perl5 and --perl6 for files that can positively identified as one or the other

Criteria for the latter:

  • file extension: .p5, .pl5, .pm5 vs .p6, .pl6, .pm6
  • shebang
  • use v* in first (non-shebang or non-comment?) line for files with generic extension

Edge cases:

  1. no shebang or use at start of file
  2. shebang disagrees with use
  3. freely intermixed p5/p6 blocks with lexical use (not possible right now, but one can dream...)

Pragmatic resolution strategy:

  1. only detect as --perl
  2. detect as both --perl5 and --perl6
  3. only detect as --perl

Alternative resolution strategy:

  • look for heuristics that discern p5 and p6 code

Personal preference is the pragmatic solution, as the latter is brittle and slow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment