How can I start an interactive console for Perl?

前端 未结 23 2356
故里飘歌
故里飘歌 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: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
    

提交回复
热议问题