deepa has asked for the wisdom of the Perl Monks concerning the following question:

Quantifier follows nothing in regex; marked by <-- HERE in m/* <-- HER +E */ at gn gxsmig_mapextver0.1.pl .
Does this error indicate that a keyword in perl occurs in that line or can it be any other error?if so,what are the possible errors? and that line has only this. if($line2=~/$mappingfield/)

Edit: g0n - code tags

Replies are listed 'Best First'.
Re: what error does this signify?
by Corion (Patriarch) on May 17, 2006 at 10:42 UTC
    Quantifier follows nothing in regex; marked by <-- HERE in m/* <-- HER +E */ at gn gxsmig_mapextver0.1.pl

    That error message means exactly what it says. There is a quantifier (in your case *) that follows nothing, that means it is at the start of the regular expression. A regular expression cannot start with *, ? or +.

    My guess is that $mappingfield starts with *. Maybe you want to read perlre and use the \Q and \E escapes to properly quote $mappingfield for use in a regular expression:

    if ($line2 =~ /\Q$mappingfield\E/) { ...
      Thanks for that info.Your reply was the solution to that problem
Re: what error does this signify?
by blazar (Canon) on May 17, 2006 at 10:41 UTC

    It means that the regex in the pattern match is not well formed. It happens to be /$mappingfield/, so it's hard to tell without seeing what's in $mappingfield. Wild guess, but I may well be wrong: you may want /\Q$mappingfield/. But then also look at index.

    BTW: use <code> tags to format code in your posts.

Re: what error does this signify?
by gellyfish (Monsignor) on May 17, 2006 at 10:47 UTC

    If means that your $mappingfield variable contains a value with the regex quantifier metacharacter '*' at the beginning - infact it appears that the variable only contains '**'. This is the same form of message you get if you do:

    perl -e'$foo='babab'; $foo =~ /*aba*/' Quantifier follows nothing in regex; marked by <-- HERE in m/* <-- HER +E aba*/ at -e line 1.
    If you intend to use metacharacters in the $mapping field then you should either use quotemeta prior to interpolating it into the pattern or shoould use \Q directive to suppress the interpretation of the metacharacters in the expression.

    /J\

Re: what error does this signify?
by GrandFather (Saint) on May 17, 2006 at 10:47 UTC

    In a regex a quantifier determines how many times something may match. There has to be a something however. A simple example is that x* matches any number of x's (including 0). It is the x that is being matched. The * say how many times it is allowed to match.

    In your sample the m/ bit introduces a regular expression match. The * is an orphaned quanifier - it has nothing to count. Most likely what you want in that case is m/.* to match any number of anything. However .* at the start of a regex match is generally redundant and can be omitted.


    DWIM is Perl's answer to Gödel