Coder Social home page Coder Social logo

perli's Introduction

npm version license

Contents

perli — introduction

perli is a multi-platform Perl REPL (read-eval-print-loop) for interactive experimentation with Perl code, convenient documentation lookups, and quick computations.

On Unix-like platforms, perli makes use of the rlwrap utility to provide command-line editing support, persistent command history, and tab-completion; see the Installation chapter below.

See the examples below, concise usage information further below, or read the manual.

Examples

Startup and help

Once you enter perli, use ? for help.

startup and help example

Automatic printing of results, use as a calculator

Results of expressions are automatically printed, which makes perli handy as an interactive calculator:

startup and help example

Results are printed with the Data::Dumper core Perl module, which means that they are reusable as input.

Inspecting a variable

The following example inspects the special %INC variable, which contains the list of loaded modules. Note the first entry, which is perli's own (optional) initialization file.

The \ prefix here is not strictly necessary, but ensures that the hashtable is printed in prettier form.

variable-inspection example

Inspecting regular-expression matches

perli provides the .remi (for regular-expression match info) command, which, in addition to an expression's own result, prints the values of the special variables that Perl maintains about the most recent successful regex match:

regex-matching example

Looking up Perl documentation

Invoking documentation overlays the REPL temporarily, as a man page would (not shown here).

By default, perli tries to guess the type of the element to look up, and invokes perldoc behind the scenes accordingly.

  • Prefix form

The following is the equivalent of perldoc perlrun:

startup and help example

  • Postfix form

This form is handy for lookups while you're in the middle of typing an expression.

The following is the equivalen of perldoc -f split:

startup and help example

  • Explicit-options form

If the "fuzzy" default lookup doesn't find anything, or shows the wrong page, you can use the prefix form with explicit perldoc options.

The following example searches the FAQs (-q) for the term while (the default lookup would have looked for the keyword).

startup and help example

Installation

Supported platforms and prerequisites

perli runs on Linux, macOS, Windows, and - as @matheusfillipe assures me - on Android, with Perl v5.6.2 or higher installed.

Using the manual installation process detailed below, perli may work on other Unix-like platforms too.

On Unix-like platforms, perli makes use of the rlwrap utility, if present,
to provide command-line editing support, persistent command history,
and simple tab completion.

On Windows, rlwrap is not available, unfortunately, but you do get
in-session history and basic command-line editing out of the box (but no tab-completion).

You can install rlwrap as follows:

  • Debian-based Linux distros such as Ubuntu:

      sudo apt-get install rlwrap
    
  • Fedora:

      sudo yum install rlwrap
    
  • macOS, via Homebrew:

      brew install rlwrap
    
  • Unix-emulation environments for Windows:

    • Cygwin (Windows):

      Re-run Cygwin's setup*.exe and install Utils > rlwrap and Base > libreadline*

    • MSYS / MinGW / Git Bash (Windows):

      Sadly, rlwrap is not offered. The next best thing is to use a native Windows Perl version, with which you get at least basic command-line editing and in-session history: Deactivate the Unix Perl with mv /bin/perl /bin/perl.inactive and install Strawberry Perl

  • All others: see rlwrap's homepage

Installation from the npm registry

Note: Even if you don't use Node.js, its package manager, npm, works across platforms and is easy to install; try curl -L http://git.io/n-install | bash

With Node.js or io.js installed, install the package as follows:

[sudo] npm install perli -g

Note:

  • Whether you need sudo depends on how you installed Node.js / io.js and whether you've changed permissions later; if you get an EACCES error, try again with sudo.
  • The -g ensures global installation and is needed to put perli in your system's $PATH.

Manual installation

Unix-like platforms

  • Download the CLI as perli.
  • Make it executable with chmod +x perli.
  • Move it or symlink it to a folder in your $PATH, such as /usr/local/bin (macOS) or /usr/bin (Linux).

Windows

  • Download the CLI as perli.pl.
  • Either move perli.pl itself into a folder in your %PATH%, or write a wrapper batch file named perli.cmd that invokes it.

Usage

Find brief usage information below; for complete documentation, once installed, run man perli (perli --man on Windows and if installed manually), or read the manual online.

$ perli --help


A simple, convenient Perl REPL for interactive experimentation.

    perli [<options>]

    --norc      skips loading of the initialization file

    The following Perl options are also supported:

    -M<name>    (repeatable) load a module and import its defaults,  
                             or activate a pragma (-M-<name> deactivates)
    -m<module>  (repeatable) load a module without importing
    -I<dir>     (repeatable) prepend <dir> to module search path (@INC)

Initialization file is ~/.perli_rc

Standard options: --help, --man, --version, --home

License

Copyright (c) 2015-2021 Michael Klement [email protected] (http://same2u.net), released under the MIT license.

Acknowledgements

This project gratefully depends on the following open-source components, according to the terms of their respective licenses.

npm dependencies below have optional suffixes denoting the type of dependency; the absence of a suffix denotes a required run-time dependency: (D) denotes a development-time-only dependency, (O) an optional dependency, and (P) a peer dependency.

npm dependencies

Changelog

Versioning complies with semantic versioning (semver).

  • v0.1.6 (2021-04-30):

    • [enhancement] Package is now installable on Android too, where @matheusfillipe assures me that perli works too (tip of the hat for the PR).
  • v0.1.5 (2021-02-23):

    • [fix] Compatibility with rlwrap version 0.45, which in combination with Perl's exec function caused a breaking change.
  • v0.1.4 (2019-02-11):

    • [fix] Ammends v0.1.3 to auto-flush stderr too.
  • v0.1.3 (2019-02-11):

    • [enhancement] Auto-flushing of stdout activated to support invocation from editors such as neovim - fixes #4
  • v0.1.2 (2015-09-30):

    • [fix] Fixed inability to define global variables (without my) in older Perl versions (e.g., v5.14).
  • v0.1.1 (2015-09-24):

    • Project-status corrected in read-me.
  • v0.1.0 (2015-09-24):

    • Initial release.

perli's People

Contributors

dependabot[bot] avatar matheusfillipe avatar mklement0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

perli's Issues

Segmentation fault when trying to run perli

I'm on Ubuntu 16.04.3 LTS with Perl 5.22.1 x86_64-linux-gnu-thread-multi.
I downloaded the perli script and copied it to /usr/bin/, added executable flag.
Also installed rlwrap.
When trying to run perl I get this: Segmentation fault (core dumped). dmesg shows: 21783.622887] perl[12937]: segfault at 5 ip 00007f01db8c59e7 sp 00007ffe26676330 error 4 in Util.so[7f01db8bd000+b000]

Any idea how to fix it?

Update: it works on my Gentoo installation though

can not get stdout when perli is running

same issue as neovim/neovim#1592

as the NOTE of neovim's job saied:

  Note: Buffered stdout/stderr data which has not been flushed by the sender
  will not trigger the on_stdout/on_stderr callback (but if the process
  ends, the on_exit callback will be invoked).
        For example, "ruby -e" buffers output, so small strings will be
        buffered unless "auto-flushing" ($stdout.sync=true) is enabled. >
          function! Receive(job_id, data, event)
            echom printf('%s: %s',a:event,string(a:data))
          endfunction
          call jobstart(['ruby', '-e',
            \ '$stdout.sync = true; 5.times do sleep 1 and puts "Hello Ruby!" end'],
            \ {'on_stdout': 'Receive'})

how about enable stdout.sync in perli?

and I am not sure if this link will help:

https://stackoverflow.com/questions/27059238/how-to-sync-print-and-warn-statements-in-perl

in this link, follow snippet is used to flush stdout:

use IO::Handle;

STDOUT->autoflush();
STDERR->autoflush();

Trailing `1` printed at repl

Here is a sample run of perli:

~ via ⬢ v14.15.4 took 8m1s 
➜ perli
# perli v0.1.5, using perl v5.32.1 - ? shows help
say "Hello, World"
Hello, World
1
say "The meaning of life is " . (0x2A)
The meaning of life is 42
1
perli>

As you can see, after each statement, it prints the number 1.

Using just perl -e, I don't get an extra 1 being printed.

~ via ⬢ v14.15.4 took 2m57s 
➜ perl -e 'use v5.10; say "Hello, World!"'
Hello, World!

I'm on Arch Linux, and installed perli from AUR

ARGUMENT ERROR: Unexpected argument(s)

I'm getting the following when I try to launch perli on macOS (installed via NPM), with rlwrap installed via Homebrew:

perli: ARGUMENT ERROR: Unexpected argument(s): --remember -f
/var/folders/mq/dw4wtwsn7dlb_q99_qcd9kdc0000gn/T/_4v7sszQoS perl -n -w -C
/var/folders/mq/dw4wtwsn7dlb_q99_qcd9kdc0000gn/T/tKZZieitU8
Use -h for help.

The /var/folders/mq/dw4wtwsn7dlb_q99_qcd9kdc0000gn/T is $TMPDIR.

This happens both with the system perl 5.18, and Homebrew's perl 5.32.

Fails with pragma

works as expected:

$ perl -e 'use bigint; print 255->to_hex'
ff

failure:

perli> use bigint
perli> 255->to_hex
Can't locate object method "to_hex" via package "255" (perhaps you forgot to
load "255"?).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.