File: test.pl

package info (click to toggle)
libterm-readline-perl-perl 1.0203-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 164 kB
  • ctags: 52
  • sloc: perl: 2,628; makefile: 48
file content (35 lines) | stat: -rw-r--r-- 1,027 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Give an argument to use stdin, stdout instead of console
# If argument starts with /dev, use it as console
BEGIN{ $ENV{PERL_RL} = 'Perl' };	# Do not test TR::Gnu !
use Term::ReadLine;

use Carp;
$SIG{__WARN__} = sub { warn Carp::longmess(@_) };


if (!@ARGV) {
  $term = new Term::ReadLine 'Simple Perl calc';
} elsif ($ARGV[0] =~ m|^/dev|) {
  open(IN,"<$ARGV[0]");
  open(OUT,">$ARGV[0]");
  $term = new Term::ReadLine 'Simple Perl calc', \*IN, \*OUT;
} else {
  $term = new Term::ReadLine 'Simple Perl calc', \*STDIN, \*STDOUT;
}
$prompt = "Enter arithmetic or Perl expression: ";
$OUT = $term->OUT || STDOUT;
%features = %{ $term->Features };
if (%features) {
  @f = %features;
  print $OUT "Features present: @f\n";
  #$term->ornaments(1) if $features{ornaments};
} else {
  print $OUT "No additional features present.\n";
}
while ( defined ($_ = $term->readline($prompt, "exit")) ) {
  $res = eval($_);
  warn $@ if $@;
  print $OUT $res, "\n" unless $@;
  $term->addhistory($_) if /\S/ and !$features{autohistory};
}