How can I start an interactive console for Perl?

前端 未结 23 2334
故里飘歌
故里飘歌 2020-12-07 07:37

How can I start an interactive console for Perl, similar to the irb command for Ruby or python for Python?

相关标签:
23条回答
  • 2020-12-07 07:49

    re.pl from Devel::REPL

    0 讨论(0)
  • 2020-12-07 07:50

    I wrote a script I call "psh":

    #! /usr/bin/perl
    
    while (<>) {
      chomp;
      my $result = eval;
      print "$_ = $result\n";
    }
    

    Whatever you type in, it evaluates in Perl:

    > gmtime(2**30)
    gmtime(2**30) = Sat Jan 10 13:37:04 2004
    
    > $x = 'foo'
    $x = 'foo' = foo
    
    > $x =~ s/o/a/g
    $x =~ s/o/a/g = 2
    
    > $x
    $x = faa
    
    0 讨论(0)
  • 2020-12-07 07:51

    I always did:

    rlwrap perl -wlne'eval;print$@if$@'
    

    With 5.10, I've switched to:

    rlwrap perl -wnE'say eval()//$@'
    

    (rlwrap is optional)

    0 讨论(0)
  • 2020-12-07 07:51

    You could look into psh here: http://gnp.github.io/psh/

    It's a full on shell (you can use it in replacement of bash for example), but uses perl syntax.. so you can create methods on the fly etc.

    0 讨论(0)
  • 2020-12-07 07:51

    See also Stylish REPL (for GNU Emacs) http://blog.jrock.us/articles/Stylish%20REPL.pod

    0 讨论(0)
  • 2020-12-07 07:53

    You can use the perl debugger on a trivial program, like so:

    perl -de1
    

    Alternatively there's Alexis Sukrieh's Perl Console application, but I haven't used it.

    0 讨论(0)
提交回复
热议问题