On 7/20/07, Mr. Shawn H. Corey <[EMAIL PROTECTED]> wrote:
Chas Owens wrote:
> The problem is that "my $c = 5" creates a lexical inside the while
> loop created by -p and it goes out of scope immediately.

Yes, that's what 'my' means.  If you do it without the 'my', it works.
And it has a lot of security problems.  But it's also quick and easy to
remember.  Like any tool, it cannot be used to solve all your problems.

Yes, but that is not what a good REPL should do with it.  Take a look
at the pugs example again.  The problem is that you are executing my
code in your context.  My code should be evaluated in a separate
context.  There should be no difference between

perl -e '
my $n = 5;
$n++;
print "$n\n";
'

and

mythical_perl_repl
my $n = 5
5
$n++
5
print "$n\n"
6
1

(note: 1 is what print would return).

In fact, here is an example using pugs:

[EMAIL PROTECTED]:~$ cat t.p6
my $c = 5;
$c++;
say $c;
[EMAIL PROTECTED]:~$ pugs t.p6
6
[EMAIL PROTECTED]:~$ pugs
  ______
/\   __ \
\ \  \/\ \ __  __  ______  ______     (P)erl6
 \ \   __//\ \/\ \/\  __ \/\  ___\    (U)ser's
  \ \  \/ \ \ \_\ \ \ \/\ \ \___  \   (G)olfing
   \ \__\  \ \____/\ \____ \/\_____\  (S)ystem
    \/__/   \/___/  \/___/\ \/____/
                      /\____/               Version: 6.2.13
                      \/___/    Copyright 2005-2006, The Pugs Contributors
--------------------------------------------------------------------
Web: http://pugscode.org/           Email: [EMAIL PROTECTED]

Welcome to Pugs -- Perl6 User's Golfing System
Type :h for help.

Loading Prelude... done.
pugs> my $c = 5
5
pugs> $c++
5
pugs> say $c
6
Bool::True
pugs>

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to