I want it to ... present the name of the command, wait for the user, then print the description, wait for the user, ad infinitum.

That makes sense, but I think that passing the output of whatis to your program via @ARGV is not the right way to go, one reason being that command-line arguments are generally split on whitespace, whereas you would have a much easier time parsing the output of whatis on a line-by-line basis, and then parse each line with a regex (or split).

There are other methods to get the output of external programs into your Perl script, practically all of which can automatically split the input into lines. The simplest is backticks (``), aka qx, and it's built in to Perl, but that can have issues with shell quoting (and thereby security, depending on usage) and error handling. So I'd recommend using a module, such as: capture from IPC::System::Simple, run3 from IPC::Run3, or capture from Capture::Tiny (there are a couple more but I like these the best).

Instead, I might use @ARGV to allow the user to pick which commands they want to be quizzed on, e.g. perl bashflash dd echo cp or perl bashflash /bin/* - note that for the latter, fileparse from File::Basename is useful to get only the name of the command.


In reply to Re: Seeking regexp @ARGV arrays Wisdom by Anonymous Monk
in thread Seeking regexp @ARGV arrays Wisdom by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.