in reply to Perl What for?

Hi NoobiePerlist,

As I know from the CB that you are using Windows and ActiveState Perl, you might like to try this. Cut and paste the first program below into Notepad and save it as play.pl

#!perl -w $|++;$,=' '; print $/,'perl> '; eval($_) || print $@,$/ and print $/,'perl> ' while(<>);

Then open a CMD window and type "perl play.pl". You end up with a prompt that looks like this perl>. This will allow you to try out simple perl programs easily, and if you make a mistake, you can use the arrow keys to retrieve the line and edit it before trying again.

I've pasted a short example session below. Have fun!

C:\test>perl play.pl perl> print 'hello world!' hello world! perl> $x = 100 perl> $y = 10 perl> print $x/$y 10 perl> print $_, "\n" for 1 .. 10 1 2 3 4 5 6 7 8 9 10 perl>

Well It's better than the Abottoire, but Yorkshire!

Replies are listed 'Best First'.
Re: Re: Perl What for?
by Django (Pilgrim) on Sep 08, 2002 at 12:25 UTC

    This is close to what you probably have in mind when saying "interactive Perl". Unfortunately, this one has some confusing behaviour with scopes, caused by the eval block:

    perl> $_ = 'Foo'; print; Foo perl> print; print; perl> my $a = 'Bar'; print $a; Bar perl> print $a; Use of uninitialized value in print at (eval 4) line 1, <> line 4.
    Writing the same commands in a file scoped script would produce different results.

    I think it might be better to go this way:
    Write a testscript in your favorite text editor. It might look like this:

    #!perl # header use warnings; # enable warnings use diagnostics; # explain warnings # code to test: print "Hey world, I'm coming!!!\n";
    Then you can save the script (e.g. "C:\test.pl"). Open your DOS command window and type in the following to run your script:
    perl C:\test.pl
    When your script succeeds, you can modify it (trying out something else), save it and run the command again.

    Hope this helps, have a lot of fun with Perl!

    ~Django
    "Why don't we ever challenge the spherical earth theory?"

      I tried to put myself in the place of a 13 y/o kid with no programming experience sitting at his Windows/ME machine staring at a screen that looked like:

      C:\>perl ashdahskjd kajhsdakjshd

      I am aware that play.pl has scoping problems, but once his copy of Programming Perl for Win32 arrives, he may arrive at the point where he knows what scoping is.

      I also thought about what would happen if his "favorite editor" is Word.

      C:\>perl test.pl Can't open perl script "test.pl": No such file or directory C:\>dir test.pl Volume in drive C has no label. Volume Serial Number is 8C87-E163 Directory of C:\ File Not Found C:\>dir test* Volume in drive C has no label. Volume Serial Number is 8C87-E163 Directory of C:\ 02/09/08 07:18a <DIR> test 02/09/08 05:16p 19,456 test.pl.doc 2 File(s) 19,456 bytes 302,397,440 bytes free C:\>perl test.pl.doc Unrecognized character \xD0 at test.pl.doc line 1. C:\>

      Well It's better than the Abottoire, but Yorkshire!
Re^2: Perl What for?
by Aristotle (Chancellor) on Sep 08, 2002 at 12:54 UTC
    Why all the effort? perl -wde1 and then just play on the prompt. :-) It also lacks the scoping problems Django mentioned.

    Makeshifts last the longest.

      Maybe this is a matter of taste, but I think the Perl debugger might be confusing for the newbie. It has its own commands and doesn't execute programs the way they would normally run. Learning one thing after another, not all simultaneously is very important. I'd start with the most essential features and move on to the "specials" later. But as always, TMWTDI -- so check it out.

      ~Django
      "Why don't we ever challenge the spherical earth theory?"

        It is quite confusing to actually try to debug with it if don't know heads from tails yet, true. The command I posted uses -e1 to supply a null source so you can just enter Perl code on the commandline though, and it'll pretty much work like an interactive interpreter then.

        Makeshifts last the longest.

      C:\>perl -wde1 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): 1 DB<1>

      "Ah! Help!"

      DB<1>h T Stack trace. s [expr] Single step [in expr]. n [expr] Next, steps over subroutine calls [in expr]. <CR> Repeat last n or s command. r Return from current subroutine. c [line|sub] Continue; optionally inserts a one-time-only breakpoin +t at the specified position. l min+incr List incr+1 lines starting at min. l min-max List lines min through max. l line List single line. l subname List first window of lines from subroutine. l $var List first window of lines from subroutine referenced +by $var. l List next window of lines. - List previous window of lines. w [line] List window around line. . Return to the executed line.

      "Um!"

        As I already replied to Django: he doesn't need any of those (besides maybe q).. just type Perl code at the command prompt.

        Makeshifts last the longest.