Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hello Monks, I have been working on a rather basic script in Perl (using the 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!


In reply to Splitting multiple commands with regex failure by CalebH

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (4)
    As of 2017-12-18 19:24 GMT
    Find Nodes?
      Voting Booth?
      What programming language do you hate the most?

      Results (496 votes). Check out past polls.