in reply to multiple-arg commands
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!
|
|---|