Loading ...
Sorry, an error occurred while loading the content.

Re: Regular Expression mathces but captures are undefined

Expand Messages
  • afbach1
    if ($temp_in =~ m/^(WJG d{4}) t([^ t]*) t([^ t]*) t([^ t]*) t/){ print Match is: n $& n ; my $sequence = $4; $sequence =~ tr/[a-z]/[A-Z]/; $sequence =~
    Message 1 of 7 , Jan 21, 2013
    • 0 Attachment
      if ($temp_in =~ m/^(WJG\d{4})\t([^\t]*)\t([^\t]*)\t([^\t]*)\t/){
      print "Match is:\n $&\n";
      my $sequence = $4;
      $sequence =~ tr/[a-z]/[A-Z]/;
      $sequence =~ s/\s//;
      my $title = $1;
      my $comment1 = $2;
      my $comment2 =$3;
      print "Found a Match\n$title\n$comment1?92;n$comment2?92;n$sequence?92;n";
      }

      Your match against "s/\s//" resets the capture vars (I don't think the
      match against "tr" does). The advantage of splitting over an RE depends
      upon how confident you are in the data formatting.

      else{

      print "Did not match.\n";

      }

      Worth adding input line number ("$.") and input (and maybe "warn" instead
      of "print") to the error msg for ease of tracking down any data problems.

      a
      ----------------------
      Andy Bach
      Systems Mangler
      Internet: andy_bach@...
      Voice: (608) 261-5738, Cell: (608) 658-1890

      "If Java had true garbage collection, most programs would delete
      themselves upon execution."
      Robert Sewell.
    Your message has been successfully submitted and would be delivered to recipients shortly.