Lines 10-35
use Term::ReadLine;
Link Here
|
10 |
use Carp; |
10 |
use Carp; |
11 |
$SIG{__WARN__} = sub { warn Carp::longmess(@_) }; |
11 |
$SIG{__WARN__} = sub { warn Carp::longmess(@_) }; |
12 |
|
12 |
|
13 |
my $ev; |
13 |
open(IN, '<', './t/input.txt') or die "Can't open input.txt, $@, $!"; |
14 |
if ($ENV{$ev = 'AUTOMATED_TESTING'} or $ENV{$ev = 'PERL_MM_NONINTERACTIVE'}) { |
14 |
$term = Term::ReadLine->new('Simple Perl calc', \*IN, \*STDOUT); |
15 |
print "1..0 # skip: \$ENV{$ev} is TRUE\n"; |
|
|
16 |
exit; |
17 |
} |
18 |
|
15 |
|
19 |
if (!@ARGV) { |
|
|
20 |
$term = new Term::ReadLine 'Simple Perl calc'; |
21 |
} elsif (@ARGV == 2) { |
22 |
open(IN,"<$ARGV[0]"); |
23 |
open(OUT,">$ARGV[1]"); |
24 |
$term = new Term::ReadLine 'Simple Perl calc', \*IN, \*OUT; |
25 |
} elsif ($ARGV[0] =~ m|^/dev|) { |
26 |
open(IN,"<$ARGV[0]"); |
27 |
open(OUT,">$ARGV[0]"); |
28 |
$term = new Term::ReadLine 'Simple Perl calc', \*IN, \*OUT; |
29 |
} else { |
30 |
$term = new Term::ReadLine 'Simple Perl calc', \*STDIN, \*STDOUT; |
31 |
$no_print = $ARGV[0] eq '--no-print'; |
32 |
} |
33 |
$prompt = "Enter arithmetic or Perl expression: "; |
16 |
$prompt = "Enter arithmetic or Perl expression: "; |
34 |
if ((my $l = $ENV{PERL_RL_TEST_PROMPT_MINLEN} || 0) > length $prompt) { |
17 |
if ((my $l = $ENV{PERL_RL_TEST_PROMPT_MINLEN} || 0) > length $prompt) { |
35 |
$prompt =~ s/(?=:)/ ' ' x ($l - length $prompt)/e; |
18 |
$prompt =~ s/(?=:)/ ' ' x ($l - length $prompt)/e; |
Lines 60-66
print $OUT <<EOP;
Link Here
|
60 |
this word should be already entered.) |
43 |
this word should be already entered.) |
61 |
|
44 |
|
62 |
EOP |
45 |
EOP |
63 |
while ( defined ($_ = $term->readline($prompt, "exit")) ) { |
46 |
while ( defined ($_ = $term->readline($prompt)) ) { |
64 |
$res = eval($_); |
47 |
$res = eval($_); |
65 |
warn $@ if $@; |
48 |
warn $@ if $@; |
66 |
print $OUT $res, "\n" unless $@ or $no_print; |
49 |
print $OUT $res, "\n" unless $@ or $no_print; |
67 |
- |
|
|