in reply to Problem with assignment for class...

$value =~ s/+/\ $1/g;
+ is a metacharacter (more accurately a quantifier) - read perldoc perlre for a full list.

Update: Mmmm. Perhaps that wasn't completely helpful.
The error message you're getting is pretty informative as far as error messages go.
The + is making the substitution/regex expect one or more of whatever character preceeds it.
In this case, there is no proceeding character, so perl complains.


If the information in this post is inaccurate, or just plain wrong, don't just downvote - please post explaining what's wrong.
That way everyone learns.

Replies are listed 'Best First'.
Re: Re: Problem with assignment for class...
by MTXperience (Initiate) on Oct 04, 2003 at 21:38 UTC
    Will this prevent the script from executing (i.e. more of a Warning than an Error such as with C++)? If so, what method should I use for replacing + with a space for processing POST input?
      You still didn't read perlre as recommended, did you?

      "+" is a quantifier. It makes no sense as the only thing in a regexp. It has to modify something. Finding a nonsensical syntax within a regular expression will cause an error, because regular expressions are a built-in part of Perl.

      If you want to match the literal character "+" you can do so by escaping it, or by metaquoting it:

      s/\+/ / # or s/\Q+\E/ /

      But you really shouldn't be parsing your own CGI parameters. Use the CGI.pm module, at least until you understand why this advice is important.

      As for additional reading: The CGI.pm POD. And perlretut, and perlre, and perlrequick all provide good reading material on regular expressions, each targeting a different stage in your learning curve.


      Dave


      "If I had my life to do over again, I'd be a plumber." -- Albert Einstein
        I realized as soon as I posted my previous reply, that the '+' had to be entered as a '/+' for syntax reasons, the reason this wasn't readily aparent is because as I said... it's in my textbook. The textbook in question is "Weaving a Website" by Susan Anderson-Freed, and has actually been quite good to this point.