Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hello Monks, I have been working on a rather basic script in Perl (using the CGI.pm module), and am combining it with Ajax. The problem is in my parsing abilities, which I am trying to handle completely in Perl, rather than in the javascript form validation with my Ajax. The Code is have so far is as follows:
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!

Caleb

In reply to Splitting multiple commands with regex failure by CalebH

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2024-04-26 02:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found