in reply to Manipulating STDIN

Better to bring in the extra text from a new source,

while (<STDIN>) { $_ = "hi test text" if some_condition; # etc }
Any chance you'll post your forth interpreter here? I'd like to see it.

Update: One way to slip in an extra STDIN is to localize the handle:

while (<STDIN>) { do { local $_ = $_; open local(*STDIN), @other_args or die $!; # do stuff } if some_condition; # more stuff }
That takes care of throwing away $_, too. BTW, your forth interpreter is 404 for me.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: Manipulating STDIN
by ChwanRen (Acolyte) on Apr 11, 2004 at 06:08 UTC
    The interpreter is here: http://yoyo.monash.edu.my/~chwanren/uploader/assignment1.txt. If I did that, wouldn't I be throwing away whatever is read from STDIN? I mean if $_ is originally 'push' and I substitute it with $_ = "hi test test", then 'push' will be ignored right? Thanks for the help :)
Re: Re: Manipulating STDIN
by ChwanRen (Acolyte) on Apr 12, 2004 at 06:58 UTC
    Yeah I'm sorry about that. Had to take it down. Don't want to get plagiarised.

    Anyway to the other replies, the reason I want to unshift to STDIN is because when my forth interpreter reads the "call" function, I want to unshift the commands stored in the variable onto STDIN. I'll elaborate. When curly braces are encountered, everything in it until the closing brace is added to a string. This string is then stored into a variable declared earlier. Like:

    pop3 { pop pop pop } store
    the string "pop pop pop" is stored into pop3 (via hash tables)

    then, when i do pop3 call, I want to unshift "pop pop pop" onto STDIN to be read.

    I've already implemented this differently by reading it everything from STDIN until EOF into a list, then handling each element of the list as though it is read from STDIN. Thus, I can unshift "pop pop pop" onto the list.

    Is there any other way to do this more elegantly?