use CGI qw(param); $command = param("command"); $command =~ m/(!\w+\s?.+?)(?=!\w)/simg; if ($command eq "") { print "Add a command, man!\n"; } if $command ne "") { if $command =~ /^\!Book/) { print "Found a Book\n\n"; } elsif ($command =~ /^\!Number/) { print "Time to log a phone number\n\n"; } print "Command has the following in it : $command and was started at \ +n"; printf "Time %s\n", scalar(localtime); print "Command 1 is $1\n"; print "And Command 2 is $2\n\n"; print "Command 3 is $3\n\n"; print "\n"; } # (!\w+\s?)(.+?(?=!\w)) is the original regex I was using
The purpose of the script is to take a lot of input through a textarea, and split it based on various 'commands', all seperated by a !Command syntax. An example above is !book, but I also have !number and a few others, and various actions need to be performed based on the command type.
I am aware that I am missing the shebang line, but at the moment I am just running this script locally on my Windows machine and it's working as is, just not spitting out the results I want (It parses the first parameters, like "command=!book this is my test book !number 1222223 !book another book" will just split out "!book this is my test book", and ignore the rest.
What I would like to happen is to have the 'commands' pushed into an empty array, and use something such as Getopt::Param to parse them, or even getopt::long.
And as for why I am not using those to start with; I just wanted a simple way to do everything using one textarea and one param, and split it into multiples from that.
Thanks Monks, and apologies for the long winded first post!
CalebIn reply to Splitting multiple commands with regex failure by CalebH
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |