Hello. I've been programming in Perl for a while and wanted to add something to my code in order to pull data from a text file. I am using regular expressions to get the data I need with the exception that once in a while, the data I need will be preceeded by an asterisk and will be skipped when my code is ran. Below is a section of code I think needs to be updated. I know I have to escape the asterisk, but not sure how given the context of my regular expression. I belive my second 'if' statement is where I would need to do this. Any help is appreciated.

<code>

while(<INFILE>){
if (m/^\s*$/) { next; }
chomp $_;
my @fields = split(/\  /,$_);
my @output;
foreach my $field(@fields){
if($field =~ /^\*?[ABMQRWY][A-Z0-9]{4}235 / ){   
push @output,$field;

}

 #     print OUTFILE "$_\n";
}

  if (@output) {
my $line = join('',@output);
print "$line\n";
print OUTFILE "$line\n";
}
}

</code>

Your regexp should probably be [\*]?[ABMQRWY][A-z0-9]{4}235, see this example.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.