Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Using perl to teach programming

by japhy (Canon)
on Jan 30, 2001 at 21:18 UTC ( [id://55275]=note: print w/replies, xml ) Need Help??


in reply to Using perl to teach programming

Since you're eval()ing the code they enter to set the variables and such, you can directly reproduce the code of the subroutine, as long as you request that they enter ONE subroutine at a time, and that subroutines are entered by themselves. This also does not work for code references. But it is a start.
# in evaluate() if (/^\s*sub\s+(\S+)/) { $WorkSpace::functions{$1} = $_; }


japhy -- Perl and Regex Hacker

Replies are listed 'Best First'.
Re: Re: Using perl to teach programming
by Falkkin (Chaplain) on Jan 30, 2001 at 21:39 UTC
    Thanks... that is a good idea. I think what I might do is this:

    Have a @code_lines array keep track of each line of code as the user enters it. This would allow me to implement a save command where the user can save their code to a file for later use. I'd need to pop values off of @code_lines for every undo command.

    Have a new subs command that retrieves everything that looks like a subroutine definition from @code_lines and prints out their contents.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://55275]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (8)
As of 2024-04-25 11:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found