inoci has asked for the wisdom of the Perl Monks concerning the following question:

ok. i'm using Expect.pm to (surprise!) automate a console program. what i occasionally need to do is parse what has been done so far, make a decision about what has happend, and then do 'a' or 'b' depending on what was dumped to the screen. normal expect matching doesn't work for what i need, so i've been doing something like this:
#jumping into the relevent bits... $command->log_file(undef); if ($command->expect(2,"/>")){ $command->log_file("$TEMPFILE") or die; print $command "<i>COMMAND</i>\r"; } if ($command->expect(5,"/>")){ $command->log_file(undef); } open (LOG, "$TEMPFILE") or die; @command_results=<LOG>; close LOG;
i'm paraphrasing, but that's the gist of it. this way i can see the results of COMMAND as @command_results. i then chop that up and have some other things happen that then prompt one of several other commands. normal expect matches don't work for me, mostly because much of this needs to be returned to the user at the end of the script. i also don't want to have to read/write a file for each time this is done for a variety of reasons, not least of which is the permissions on the folder this will be run from (nothing i can control).

so, i have 2 questions:
1. can i have a filehandle to point the expect log at that isn't actually a file?
2. is there a better way to grab the output of a command with Expect.pm than using the log file?

edited: Tue Apr 8 22:30:17 2003 by jeffa - code tags

Replies are listed 'Best First'.
Re: 'virtual' filehandles...
by graff (Chancellor) on Apr 08, 2003 at 23:34 UTC
    Check out IO::Scalar -- this looks like it does what you want, i.e. makes a scalar behave like a file handle, so you can "print" to it. (There's also IO::ScalarArray.)
      In 5.8 you can also open a scalar:
      open SCANDLE, \$scalar; # use a 3 argument open to specify mode


      -nuffin
      zz zZ Z Z #!perl