For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > September 2006 > An interactive interpreter/shell?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author An interactive interpreter/shell?
robb@acm.org

2006-09-22, 6:59 pm

Hi,

Is there a shell out there that has functionality like Python's
interactive interpreter? I've seen references to a few things out
there (two different projects named psh?) But they don't look like
they're currently being worked on, or are up to date.

Thanks,
Robb

usenet@DavidFilmer.com

2006-09-22, 6:59 pm

robb@acm.org wrote:
> Is there a shell out there


perldoc -q shell
Is there a Perl shell?

--
David Filmer (http://DavidFilmer.com)

usenet@DavidFilmer.com

2006-09-22, 6:59 pm

robb@acm.org wrote:
> Is there a shell out there


perldoc -q shell
Is there a Perl shell?

--
David Filmer (http://DavidFilmer.com)

Michele Dondi

2006-09-23, 7:59 am

On 22 Sep 2006 13:46:39 -0700, "robb@acm.org" <robb@acm.org> wrote:

>Is there a shell out there that has functionality like Python's
>interactive interpreter? I've seen references to a few things out


Yes, but it has a strange name. It's called

perl -de42

>there (two different projects named psh?) But they don't look like
>they're currently being worked on, or are up to date.


That's a different thing, anyway.


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{po
p^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
robb@acm.org

2006-09-24, 4:00 am

>
> perldoc -q shell
> Is there a Perl shell?


Thanks - that was helpful.

robb@acm.org

2006-09-25, 6:59 pm

Michele Dondi wrote:
> On 22 Sep 2006 13:46:39 -0700, "robb@acm.org" <robb@acm.org> wrote:
>
>
> Yes, but it has a strange name. It's called
>
> perl -de42


Cute response, but OT.

Uri Guttman

2006-09-25, 10:00 pm

>>>>> "ro" == robb@acm org <robb@acm.org> writes:

ro> Michele Dondi wrote:[color=darkred]

ro> Cute response, but OT.

again, you are very wrong. that is an actual perl shell. you can type
perl commands on a line and they get executed. does a shell do much more
than that? do you even understand what that command does?

uri

--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Tad McClellan

2006-09-26, 4:00 am

robb@acm.org <robb@acm.org> wrote:
> Michele Dondi wrote:
>
> Cute response, but OT.



Invoking perl is not off-topic in the Perl newsgroup.


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
robb@acm.org

2006-09-26, 4:00 am

>
> again, you are very wrong. that is an actual perl shell.
>


"has functionality like Python's"

?

Uri Guttman

2006-09-26, 4:00 am

>>>>> "ro" == robb@acm org <robb@acm.org> writes:
[color=darkred]

ro> "has functionality like Python's"

ro> ?

has posting attributions? has grammar sensible? has context?

uri

--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Michele Dondi

2006-09-26, 6:59 pm

On 25 Sep 2006 17:01:50 -0700, "robb@acm.org" <robb@acm.org> wrote:

>
>Cute response, but OT.


Is it? I see that you mention yourself psh and others pointed you to
perl-{based,oriented} *command* shells, but since you talked about
"Python's interactive interpreter" I thought that the closest thing
would have been an... interactive Perl interpreter, which is what I
pointed you to. If you do not find that satisfying, care to say why?

$ perl -de42

Loading DB routines from perl5db.pl version 1.28
Editor support available.

Enter h or `h h' for help, or `man perldebug' for more help.

main::(-e:1): 42
DB<1> print "Hello world\n"
Hello world

DB<2> my $x=2;

DB<3> my $y=3;

DB<4> my $z=$x+$y;

DB<5> exit; # I'm tired
Debugged program terminated. Use q to quit or R to restart,
use O inhibit_exit to avoid stopping after program termination,
h q, h R or h O to get additional info.
DB<6> q


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{po
p^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
robb@acm.org

2006-09-26, 6:59 pm

Michele Dondi wrote:
> ...I see that you mention yourself psh and others pointed you to
> perl-{based,oriented} *command* shells, but since you talked about
> "Python's interactive interpreter" I thought that the closest thing
> would have been an... interactive Perl interpreter, which is what I
> pointed you to. If you do not find that satisfying, care to say why?


Yes, you're right. I'm sorry about the sarcastic reply earlier.
Here's a description of a few things that the perl interpreter doesn't
do interactively:

http://dev.perl.org/perl6/rfc/184.html

The Python interpreter offers a lot more, though. As a Python
developer, I'm used to being able to start the interpreter, instantiate
some of my new classes I've written, invoke methods, determine the
types of the objects.

The Python interpreter feels a lot like Smalltalk without the graphic
interface.

It's a common development style for Python programmers, and I was
hoping to use it with my Perl development. Here's an example of what I
mean. I'd love to find an environment that provides this kind of
convenient syntax (uses only the syntax of the language itself), plus
has these useful features in Perl. Automatic evaluation of names,
high-level user feedback, etc:
[color=darkred]
.... def bark(self):
.... print "Woof"
....[color=darkred]
<class '__main__.Dog'>[color=darkred]
<unbound method Dog.bark>[color=darkred]
<__main__.Dog object at 0x403d7cac>[color=darkred]
<bound method Dog.bark of <__main__.Dog object at 0x403d7cac>>[color=darkred]
Woof[color=darkred]
<class '__main__.Dog'>[color=darkred]
<type 'type'>[color=darkred]
'This is a string'[color=darkred]
['__add__', '__class__', '__contains__', '__delattr__', '__doc__',
'__eq__', '__ge__', '__getattribute__', '__getitem__',
'__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__',
'__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__',
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__',
'__rmul__', '__setattr__', '__str__', 'capitalize', 'center', 'count',
'decode', 'encode', 'endswith', 'expandtabs', 'find', 'index',
'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle',
'isupper', 'join', 'ljust', 'lower', 'lstrip', 'replace', 'rfind',
'rindex', 'rjust', 'rsplit', 'rstrip', 'split', 'splitlines',
'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper',
'zfill'][color=darkred]
'THIS IS A STRING'[color=darkred]
<type 'str'>[color=darkred]
<type 'builtin_function_or_method'>

robb@acm.org

2006-09-26, 6:59 pm

robb@acm.org wrote:

> ...As a Python
> developer, I'm used to being able to start the interpreter, instantiate
> some of my new classes I've written, invoke methods, determine the
> types of the objects.
>


And, I didn't get too far using the perl interpreter. Maybe I did
something wrong? But also - it's not clear to me that this kind of
work is supported:

DB<1> print "hello\n";
DB<2> use lib '/home/web/lib/perl';
DB<3> use Trillium::Info;
DB<4> my $info = Trillium::Info->new();
DB<5> $info;

DB<6> $info->is_valid_tld('lclark.edu');
Can't call method "is_valid_tld" on an undefined value at (eval
21)[/usr/local/lib/perl5/5.8.0/perl5db.pl:17] line 2.

DB<7> print $info;

DB<8>

thisisbradley@gmail.com

2006-09-26, 6:59 pm


robb@acm.org wrote:
> And, I didn't get too far using the perl interpreter. Maybe I did
> something wrong? But also - it's not clear to me that this kind of
> work is supported:
>
> DB<1> print "hello\n";
> DB<2> use lib '/home/web/lib/perl';
> DB<3> use Trillium::Info;
> DB<4> my $info = Trillium::Info->new();
> DB<5> $info;
>
> DB<6> $info->is_valid_tld('lclark.edu');
> Can't call method "is_valid_tld" on an undefined value at (eval
> 21)[/usr/local/lib/perl5/5.8.0/perl5db.pl:17] line 2.


Try it without the 'my':

M:\>perl -de42
Default die handler restored.

Loading DB routines from perl5db.pl version 1.07
Editor support available.

Enter h or `h h' for help, or `perldoc perldebug' for more help.

main::(-e:1): 42
DB<1> use CGI

DB<2> $x = CGI->new

DB<3> x $x
0 CGI=HASH(0x1af3d28)
'.charset' => 'ISO-8859-1'
'.fieldnames' => HASH(0x1ad0378)
empty hash
'.parameters' => ARRAY(0x19b90f0)
empty array
DB<4> my $y = CGI->new

DB<5> x $y
0 undef
DB<6>


Bradley

Mumia W. (reading news)

2006-09-26, 6:59 pm

On 09/26/2006 12:28 PM, robb@acm.org wrote:
> robb@acm.org wrote:
>
>
> And, I didn't get too far using the perl interpreter. Maybe I did
> something wrong? But also - it's not clear to me that this kind of
> work is supported:
>
> DB<1> print "hello\n";
> DB<2> use lib '/home/web/lib/perl';
> DB<3> use Trillium::Info;
> DB<4> my $info = Trillium::Info->new();


I've found "my" to be tricky in the perl debugger. The variable is
probably trapped in an invisible, inaccessible block. Don't use "my" on
variables that you define at the debugger prompt.

However, my should work on scripts in the debugger.

> DB<5> $info;


By itself, "$info;" is a useless statement; you probably meant "print
$info;"

And since the $info created on line 4 (DB<4> ) is trapped in an invisible
block, this info (on line 5) is undefined.

>
> DB<6> $info->is_valid_tld('lclark.edu');
> Can't call method "is_valid_tld" on an undefined value at (eval
> 21)[/usr/local/lib/perl5/5.8.0/perl5db.pl:17] line 2.
>
> DB<7> print $info;
>


Without warnings enabled, attempts to print undefined values display
nothing.

> DB<8>
>


I hope this helps.
--
paduille.4058.mumia.w@earthlink.net

thisisbradley@gmail.com

2006-09-26, 6:59 pm

Mumia W. (reading news) wrote:
> On 09/26/2006 12:28 PM, robb@acm.org wrote:
>
> I've found "my" to be tricky in the perl debugger. The variable is
> probably trapped in an invisible, inaccessible block.


perldebug says:

Any command not recognized by the debugger is directly executed
(eval'd) as Perl code in the current package.

So when using the debugger interactively, lexically scoped variables do
not propogate across multiple statements.

>
> By itself, "$info;" is a useless statement; you probably meant "print
> $info;"


Given that $info is an instance of Trillium::Info, I'd probably use 'x
$info' to recursively pretty-print its values. 'print' only outputs
the package name and its memory address.

> Without warnings enabled, attempts to print undefined values display
> nothing.


Strangely, I only receive a warning when turning on warnings via
'-wde42':

X:\S60>perl -de42
Default die handler restored.

Loading DB routines from perl5db.pl version 1.07
Editor support available.

Enter h or `h h' for help, or `perldoc perldebug' for more help.

main::(-e:1): 42
DB<1> use warnings;

DB<2> print $e

DB<3>

Bradley

Michele Dondi

2006-09-27, 4:00 am

On Tue, 26 Sep 2006 20:31:51 GMT, "Mumia W. (reading news)"
<paduille.4058.mumia.w@earthlink.net> wrote:

>
>By itself, "$info;" is a useless statement; you probably meant "print
>$info;"


Or

x $info


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{po
p^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
Michele Dondi

2006-09-27, 4:00 am

On 26 Sep 2006 10:22:46 -0700, "robb@acm.org" <robb@acm.org> wrote:

>Yes, you're right. I'm sorry about the sarcastic reply earlier.
>Here's a description of a few things that the perl interpreter doesn't
>do interactively:
>
> http://dev.perl.org/perl6/rfc/184.html


Err, well, yes: it's a debugger and not an actual interpreter,
although it offers much of the functionality of the latter. It has
some commands and stuff that is not a command gets eval()'d in the
context of the current package. So you may still write basically any
amount of code you like provided it's all on one line.

>The Python interpreter offers a lot more, though. As a Python


I bet it does. Though evidence is that Perl programmers do not really
suffer from the lack of such a beast. And the debugger is more than
enough to type some perl interactively.

>developer, I'm used to being able to start the interpreter, instantiate
>some of my new classes I've written, invoke methods, determine the
>types of the objects.


All this *is* possibile in the debugger.

>The Python interpreter feels a lot like Smalltalk without the graphic
>interface.


Not having any more experience with Smalltalk than with Python, this
doesn't help much. Still, I have some experience with languages that
have an interactive interpreter, but I don't feel the need for one in
Perl.

>It's a common development style for Python programmers, and I was
>hoping to use it with my Perl development. Here's an example of what I


I guess you will have to abandon your hope...
[color=darkred]
>... def bark(self):
>... print "Woof"
>...
><class '__main__.Dog'>

DB<1> package Dog; sub bark { print "Woof" }

DB<2> x *Dog
0 *main::Dog
DB<3> Dog->bark
Woof


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{po
p^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
Michele Dondi

2006-09-27, 4:00 am

On 26 Sep 2006 10:28:09 -0700, "robb@acm.org" <robb@acm.org> wrote:

>And, I didn't get too far using the perl interpreter. Maybe I did
>something wrong? But also - it's not clear to me that this kind of
>work is supported:
>
>DB<1> print "hello\n";
>DB<2> use lib '/home/web/lib/perl';
>DB<3> use Trillium::Info;
>DB<4> my $info = Trillium::Info->new();


From perldoc perldebug:

: Note that the said "eval" is bound by an implicit scope. As a result
: any newly introduced lexical variable or any modified capture buffer
: content is lost after the eval. The debugger is a nice environment to
: learn Perl, but if you interactively experiment using material which
: should be in the same scope, stuff it in one line.

Sorry!


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{po
p^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
Brian Raven

2006-09-27, 7:01 pm

Michele Dondi <bik.mido@tiscalinet.it> writes:

> On 26 Sep 2006 10:22:46 -0700, "robb@acm.org" <robb@acm.org> wrote:
> Err, well, yes: it's a debugger and not an actual interpreter,
> although it offers much of the functionality of the latter. It has
> some commands and stuff that is not a command gets eval()'d in the
> context of the current package. So you may still write basically any
> amount of code you like provided it's all on one line.


See the section on multiline commands in 'perldoc
perldebug'. Essentially, newlines can be escaped with ''.

HTH

--
Brian Raven
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com