Skip to content

Latest commit

 

History

History
244 lines (183 loc) · 5.32 KB

File metadata and controls

244 lines (183 loc) · 5.32 KB

CLI Options Reference

Command-line options for the jperl command.

Synopsis

jperl [options] [program | -e 'command'] [arguments]

Common Options

Basic Usage

  • -e 'command' - Execute command

    ./jperl -e 'print "Hello\n"'
  • -E 'command' - Execute command with all features enabled

    ./jperl -E 'say "Hello"'  # say requires -E
  • -c - Check syntax only (no execution)

    ./jperl -c script.pl
  • -v - Print version

    ./jperl -v
  • -h or -? - Show help

    ./jperl -h

Module and Library

  • -I dir - Add directory to @INC (module search path)

    ./jperl -I/path/to/lib script.pl
  • -M module - Load module (like use module)

    ./jperl -MJSON -E 'say encode_json({a => 1})'
  • -m module - Load module (like use module ())

    ./jperl -mJSON script.pl

Input Processing

  • -n - Process input line-by-line (implicit loop, no print)

    echo -e "foo\nbar" | ./jperl -ne 'print if /foo/'
  • -p - Like -n but print $_ after each iteration

    echo -e "foo\nbar" | ./jperl -pe 's/foo/baz/'
  • -a - Autosplit mode (splits $_ into @F)

    echo "a b c" | ./jperl -ane 'print "$F[1]\n"'  # Prints: b
  • -F pattern - Split pattern for -a (default: whitespace)

    echo "a:b:c" | ./jperl -F: -ane 'print "$F[1]\n"'  # Prints: b
  • -0[octal] - Input record separator (default: newline)

    # Read null-terminated records
    ./jperl -0 -ne 'print' file.txt
    
    # Read entire file as one record
    ./jperl -0777 -ne 'print length' file.txt
  • -l[octal] - Enable line ending processing

    # Auto-chomp and add newline to print
    ./jperl -lne 'print uc' file.txt
  • -i[extension] - Edit files in-place

    # In-place edit with backup
    ./jperl -i.bak -pe 's/foo/bar/g' file.txt
    
    # In-place edit without backup
    ./jperl -i -pe 's/foo/bar/g' file.txt

Script Arguments

  • -s - Enable switch parsing for script
    # script.pl can access -foo as $foo
    ./jperl -s script.pl -foo=bar

Warnings and Strictness

  • -w - Enable warnings

    ./jperl -w script.pl
  • -W - Enable all warnings

    ./jperl -W script.pl
  • -X - Disable all warnings

    ./jperl -X script.pl

Other Options

  • -x[dir] - Extract script from message

    ./jperl -x script.txt
  • -S - Search for script in PATH

    ./jperl -S script.pl
  • -g - Read all input before executing (slurp mode for -n/-p)

Execution Mode Options

  • --interpreter - Use interpreter mode instead of compiler mode

    ./jperl --interpreter script.pl

    Compiler mode (default) generates JVM bytecode for high performance:

    • High performance after JIT warmup (~82M ops/sec)
    • Better for long-running programs
    • Full Java integration and optimization

    Interpreter mode executes Perl bytecode directly in a register-based VM without generating JVM bytecode. It offers:

    • Faster startup time (no JVM class generation overhead)
    • Ideal for short-lived scripts and eval STRING
    • Performance: ~47M ops/sec (1.75x slower than compiler, within 2-5x target)

Debugging Options

  • --debug - Show debug information

    ./jperl --debug -E 'say "test"'
  • --disassemble - Show disassembled bytecode

    # Show JVM bytecode (compiler mode)
    ./jperl --disassemble script.pl
    
    # Show interpreter bytecode (interpreter mode)
    ./jperl --interpreter --disassemble script.pl
  • --tokenize - Show lexer output

    ./jperl --tokenize -E '$x = 1'
  • --parse - Show parser output (AST)

    ./jperl --parse -E 'my $x = 1'
  • -V - Print detailed configuration

    ./jperl -V

Environment Variables

  • PERL5LIB - Directories to add to @INC

    export PERL5LIB=/path/to/lib
    ./jperl script.pl
  • PERL5OPT - Default options for perl

    export PERL5OPT='-Mwarnings -Mstrict'
    ./jperl script.pl

Combining Options

Options can be combined for powerful one-liners:

# Replace text in all files
./jperl -i.bak -pe 's/old/new/g' *.txt

# Process CSV with auto-split
./jperl -F, -ane 'print "$F[2]\n"' data.csv

# Count lines matching pattern
./jperl -ne 'END {print $.} /pattern/ or next' file.txt

# Sum numbers in a column
./jperl -ane '$sum += $F[2]; END {print $sum}' data.txt

# Use interpreter mode for quick scripts
./jperl --interpreter -E 'say "Hello, World!"'

# Debug interpreter bytecode
./jperl --interpreter --disassemble -E 'my $x = 1; $x += 2'

Not Implemented

The following standard Perl options are not yet implemented:

  • -T - Taint checks
  • -t - Taint checks with warnings
  • -u - Dumps core after compiling
  • -U - Allows unsafe operations
  • -d[t][:debugger] - Run under debugger
  • -D[number/list] - Set debugging flags
  • -C [number/list] - Control Unicode features

See Also