Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!apple!veritas!amdcad!sono!porky!mayer From: mayer@sono.uucp (Ronald &) Newsgroups: comp.lang.perl Subject: using perl interactively Message-ID: Date: 21 May 91 18:54:29 GMT Sender: mayer@sono.uucp (Ronald Mayer) Distribution: comp Organization: Acuson; Mountain View, California Lines: 34 Has anyone written a good interface for using perl interactively? (kinda like a over-featured calculator with string and array operators, and access to unix commands and system calls) I guess what I'm looking for is something like this: #!/usr/local/bin/perl $|=1; # good in interactive programs $nprompt = ">"; # normal prompt $cprompt = ">>"; # continuation prompt while(1) { print "$input",$input?$cprompt:$nprompt; # print the prompt $input .= <>; # get or append to input $_ = @_ = eval $input; # eval input if (!($@)) { # success print "@_\n"; # show result of eval } elsif ($@ =~ /syntax error in file \(eval\) at line [0-9]+, at EOF/) { next; # probably continued statement } else { # probably syntax error print $@; # show eval error message } undef($input); # clear input } which seems to do fine for all one line statements and many (but probably not most) multi-line commands like while loops. Is there a better way of guessing whether a failed eval failed because of a 'real' syntax error or if the string being eval'd is a potentially legal but incomplete perl statement? Ron Mayer mayer@sono.uucp sun!sono!mayer