The question has different answers depending on the meaning of "multiple-arg."

If you mean "multiple command-line arguments," as in perl myscript.pl file1 file2 file3 where file[1-3] are the "multiple arguments," then there's a global array @ARGV that has the one element per argument. In this example, $ARGV[0] eq 'file1', $ARGV[1] eq 'file2', etc. The name of the script is in the special variable $0.

If you mean how do you take a string like "/tell ahbeyra moo" that someone would type into the chatterbox, and parse it into separate words (based on spaces for example), one simple way you could do this is with split. As in, my @args = split /\s+/, $string, where $string had the "/tell" command in it. This would make @args an array with 3 elements, "/tell", "ahbeyra", and "moo." You will get empty strings at the beginning of the array if $string starts with spaces, so be careful there.

Or, if you want to parse a string into, say, "/tell" and the rest of the message, you can use regular expressions with m// and friends, like my ($cmd, $phrase) = ($string =~ m[\s*(/\w+)\s+(.*)])

This will put "/tell" into $cmd (in the example) and "ahbeyra moo" into $phrase. You should really look into perlre if you're interested in this sort of thing; it's a wealth of information (oftentimes too much ;)

Hope this helps!


In reply to Re: multiple-arg commands by blackmateria
in thread multiple-arg commands by Ahbeyra

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.