Important alert: (current site time 7/15/2013 9:22:42 PM EDT)
 

VB icon

Command-Parameter Destinguisher

Email
Submitted on: 1/28/2005 11:03:35 PM
By: Leonid Grinberg  
Level: Beginner
User Rating: By 1 Users
Compatibility: 5.0 (all versions)
Views: 6167
(About the author)
 
     This is a very simple script that allows a program to be able to take in command-parameter like input (for example in a text-based game, 'eat pie' or something like that) find the command (eat) and parameter (pie), and save them to different variables ($command and $param) which allows the program to use them for it's own purposes.
 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
=**************************************
= for :Command-Parameter Destinguisher
=**************************************
This code is saved under the GNU General Public Licence (http://www.gnu.org/licenses/gpl.txt).
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
=**************************************
= Name: Command-Parameter Destinguisher
= Description:This is a very simple script that allows a program to be able to take in command-parameter like input (for example in a text-based game, 'eat pie' or something like that) find the command (eat) and parameter (pie), and save them to different variables ($command and $param) which allows the program to use them for it's own purposes.
= By: Leonid Grinberg
=
=This code is copyrighted and has= limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=619&lngWId=6=for details.=**************************************

#This program is free software; you can #redistribute it and/or modify
#it under the terms of the GNU General Public #License as published by
#the Free Software Foundation; either version 2 of #the License, or
#(at your option) any later version.
#This program is distributed in the hope that it #will be useful,
#but WITHOUT ANY WARRANTY; without even the #implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR #PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU #General Public License
#along with this program; if not, write to the #Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, #Boston, MA 02111-1307 USA
#Copyright 2005, Leonid Grinberg, All Rights Reserved
$spacechar = " "; # the character that index searches for (should generally be space
print "What is the command?\n";
$fcommand = <stdin>; # enters command w/ parameter
chop($fcommand); # gets rid of newline
$commlen = length($fcommand); # the length of the total command; ZERO BASED!!!
$space = index($fcommand,$spacechar); # finds the position of the space
$origcomm = $fcommand; # saves the original command
$paramnum = $commlen - $space; # finds where the parameter starts
for ($counter = 0; $counter < $paramnum; $counter++) # determines what the command w/o the parameter is...
{
chop($fcommand); # deletes a character from the parameter
}
$command = $fcommand; # this is the actual command
$fcommand = $origcomm; # sets back to command w/ parameter
$param = substr($fcommand, $space+1, $paramnum); # returns the parameter by itself
print "The command is $command and the parameter is $param.\n";


Other 3 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

1/28/2005 11:10:24 PMLeonid Grinberg

Sorry, but PlanetSourceCode made it look all ugly... There are supposed to be indents and blank lines, etc.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.