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

Without using perl modules, how can I have Perl call a program and fill in values for it? For an example, having Perl call /bin/passwd and have it fill in the new and old password information.

edited: Fri Mar 28 20:23:59 2003 by jeffa - title change (was: Auto Fill w/o modules)

Replies are listed 'Best First'.
Re: IPC/Expect w/o modules
by graff (Chancellor) on Mar 28, 2003 at 06:27 UTC
    Well, if you don't want your code to have "use Expect;" in it, then you might consider looking at Expect.pm, taking the parts from it that matter for your application, and copying them into your code.

    Note that /bin/passwd is an especially tough example for this sort of thing -- to quote Abigail-II's reply to a another recent thread on a similar topic: ... passwd reads directly from the (pseudo)-terminal, not from STDIN.

    update: my suggestion of copying from the module wasn't intended to be facetious -- well, not entirely -- but by starting down that path, you will get a good sense of the handicap that comes with seeking a no-modules solution for this sort of problem. I haven't looked at the Expect.pm source code -- it might very well use (depend on) other modules, and you'd need to copy relevant code from them as well.

    Granted, there is the rare situation where module installation is beyond your personal control, and you need a work-around. But then again, for things that involve unix user-accounts and related security issues, we should not expect (or want) work-arounds to be an easy matter -- e.g. if it's hard or impossible to execute /bin/passwd via a CGI script (e.g. because the sysadmin won't provide Expect.pm in this context), that's not an unreasonable situation, and it would be quite foolish to circumvent that.

      ... e.g. if it's hard or impossible to execute /bin/passwd via a CGI script (e.g. because the sysadmin won't provide Expect.pm in this context), that's not an unreasonable situation, and it would be quite foolish to circumvent that

      and if you can circumvent it (since passwd is setuid root), you might as well install the modules while you're at it.

      -derby

Re: IPC/Expect w/o modules
by vek (Prior) on Mar 28, 2003 at 06:36 UTC
    Any particular reason why you don't want to use modules? As a general rule of thumb you'll find that using modules instead of reinventing the wheel is generally considered a good thing :-)

    -- vek --