in reply to No grokkage on regex search/replace
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Okay! Okay! You Talked Me Into It!!! :)
by bluethundr (Pilgrim) on May 25, 2004 at 02:29 UTC |