First, your code shouldn't even compile; your s/// operator doesn't have a terminating '/' character. Be sure to paste actual code snippets wherever possible.

Now for the analysis:

One problem is that metacharacter-classes and quantifiers are meaningless on the right-side (the replacement side) of an s/// operator. You can't say, "s/\s+(\w+)/$1\s+/;"

That should be written something more along the lines of:

# Wrong: $phr =~ s/\s+(w+)\s+(w+)/$2\s+$1; $phr =~ s/\b(\w+)(\s+)(\w+)\b/$3$2$1/;

Also, I really do think you're doing yourself a disservice by not picking up a copy of the Llama book, "Learning Perl." That is the introductory course of choice. It just seems like your code has a lot of non-perlish nuggets. For example, what is your initargs() subroutine supposed to be doing? And why is it passing variables around through osmosis instead of through proper parameter lists and return values?

And don't forget:

use warnings; use diagnostics;

.... at least while learning.

Update: One more thing... Please be careful to learn about security issues if you plan to place an online CGI script that deals with money, takes user input, etc. I really think that's too important to gloss over in your first 21 days of Perl programming. We've recently seen what happened to Nik, who ignored warnings about CGI security concerns. Putting a script where others will be executing it (such as CGI) is not something to be done carelessly.


Dave


In reply to Re: No grokkage on regex search/replace by davido
in thread No grokkage on regex search/replace by bluethundr

Title:
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, details, 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, summary, 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.