[sf-perl] Unmatched [ in regex; marked by <-- HERE in m/[ <-- HERE NO/

David Fetter david at fetter.org
Mon Jan 15 15:53:01 PST 2007


On Mon, Jan 15, 2007 at 04:31:11PM -0700, Loo, Peter # PHX wrote:
> 
>    Hello,

Hi

>    I am getting the following error when I hit the following record when trying
>    to m// the field "[NO".
> 
>    my $field = substr($_, $offset, $length);
> 
>    elsif ($field =~ m/^[0-9]*\s+[0-9]$/ || $field =~ m/\W+/) {
                      ^^^^^^^^^^^^^^^^^^^
This is better written as

    $field =~ m(
                \A    # Start
                \d*   # 0 or more digits
                \s+   # some whitespace
                \d    # a digit
                \z    # End
               )mx

> When I leave in the part "|| $field =~ m/\W+/)" the error goes away, but
> without this, I am getting an error.

It would help a lot if you sent a self-contained example that we could
test :)

Cheers,
D (who just hates working too hard)
-- 
David Fetter <david at fetter.org> http://fetter.org/
phone: +1 415 235 3778        AIM: dfetter666
                              Skype: davidfetter

Remember to vote!


More information about the SanFrancisco-pm mailing list