in reply to Re: Getting regular expression right
in thread Getting regular expression right

if (/$_[0] =~ /^([^:]+):([^|]+)(?:\|(.*))?$/ || $_[0] =~ /^([^|)+)\|(.*)$/) { @key{qw /name definition altdefinition/} = ($1, $2, defined $3 ? $ +3 : "") }
I cannot get this example working? And should @key be %key?

Replies are listed 'Best First'.
Re^3: Getting regular expression right
by Anonymous Monk on Feb 15, 2005 at 12:12 UTC
    I cannot get this example working?

    If you say so. Why not? No match? Error? Match when it shouldn't? Wrong content of variables? Explain yourself.

    And should @key be %key?

    No.

      There seems to be error with the regex.

      Error when pasted to my script:
      [mellimik@localhost cgi-bin]$ perl -cw formCreator.pl Scalar found where operator expected at formCreator.pl line 286, near +"?:\|(.*))?$/" (Missing operator before $/?) syntax error at formCreator.pl line 286, near "[^" formCreator.pl had compilation errors.
      It's the character class inside the second last memory parentheses:
      if (/$_[0] =~ /^([^:]+):([^|]+)(?:\|(.*))?$/ || $_[0] =~ /^([^|)+)\|(.*)$/) {
      Should be like this:
      if (/$_[0] =~ /^([^:]+):([^|]+)(?:\|(.*))?$/ || $_[0] =~ /^([^|])+)\|(.*)$/) {
        I guess that should be:
        if ($_[0] =~ /^([^:]+):([^|]+)(?:\|(.*))?$/ || $_[0] =~ /^([^|])+\|(.*)$/) {