in reply to Unmatched [ in regex; marked by <-- HERE in m/[ <-- HERE ^]/

> any ideas?

not really, cause it does what you told it to do...

DB<101> @a = 'a'..'d' => ("a", "b", "c", "d") DB<102> 'c' =~ /[^@a]/ DB<103> 'c' =~ /[@a]/ => 1 DB<104> $re=qr/[^@a]/ => qr/[^a b c d]/

... but wrongly, please note that whitespace is now excluded too!

Apparently you're not showing the whole code.

Are you sure about the content of @aminos?

And why do you exclude 23 letters of the alphabet (in random order) instead of matching the remaining 3?

edit

your array @aminos is empty, thats why /[^]/ tries to exclude ']' within an unterminated character class.

Cheers Rolf

( addicted to the Perl Programming Language)

Replies are listed 'Best First'.
Re^2: Unmatched [ in regex; marked by <-- HERE in m/[ <-- HERE ^]/
by madM (Beadle) on Apr 29, 2014 at 01:11 UTC
    i know what it is.. the @aminos array is empty when the script runs... im starting the script with the command line using getopt::long i declare the array aminos at the first of the script and the other part is in a soubrutine.. so when i call the subroutine with the option sub ... the array @aminos is empty in the subroutine... do you know why is this happening? something like this:
    GetOptions ( 'sub' => \& ) @aminos= qw (A R N D C Q E G H I L K M F P S T W Y V B Z X); sub a { if( "$substr1$substr2" =~ /[^@aminos]/ ) ... }
      > the @aminos array is empty when the script runs.

      yep I just deciphered it from the error msg.

      update

      > do you know why is this happening?

      the initialization of @aminos is never executed.

      using strict and warnings might have shown you.

      either put the initialization into the sub or declare a constant (string please!).

      update

      darn, constants are not interpolated in strings or regexes.

      you have to define a constant regex:

      DB<131> use constant REGEX=>qr/[^ABCD]/ DB<132> 'C' =~ REGEX DB<133> 'Z' =~ REGEX => 1

      Cheers Rolf

      ( addicted to the Perl Programming Language)

        darn, constants are not interpolated in strings or regexes.

        As I understand it, even with use constant, a constant in Perl is an in line sub. IE:

        use constant PI => 4 * atan2(1, 1);

        is the short hand for

        sub PI { 4 * atan2(1, 1); }

        Which, after compile time constant expression evaluation, simplifies to:

        sub PI { 3.1415926536; # to the precision available on the machine running +the program }

        which the compiler can then in line where it would otherwise put a sub call.

      As mentioned before, you're invoking the subroutine (it's invoked during  GetOptions() processing) before the array is initialized. Eg.:

      c:\@Work\Perl\monks>perl -wMstrict -le "S('before'); ;; my @ra = qw(A C T G); ;; S('after'); ;; sub S { print qq{$_[0] initialization: [@ra] }; } " before initialization: [] after initialization: [A C T G]