The following code reads the content of a (simulated) file, extracts the two values and tests them. A regex is defined for each field. They are combined into a single regex which describes the rest of the line and specifies that both values should be extracted. If the match is successful, both values are tested.
use strict;
use warnings;
use Test::Simple tests => 3;
my $fname = \do {
my $line = "BOGUS PPI3_SYNY3 276 aa contentar BCT 13-NOV-2019\n";
};
open my $FH, '<', $fname or die "Cannot open $fname for input";
my $content = <$FH>;
close $FH;
my $get_bogus = qr/ [A-Z0-9_]+ /x;
my $get_acid = qr/ [0-9]+\s[a-z]+ /x;
my ( $bogus, $acids )
= $content =~ / BOGUS \s+ ($get_bogus) \s+ ($get_acid) /x;
if (ok( ( defined($bogus) and defined($acids) ), 'Match') ) {
ok( $bogus eq "PPI3_SYNY3" , "extracted '$bogus'");
ok( $acids eq '276 aa', "extracted '$acids'");
}
OUTPUT:
1..3
ok 1 - Match
ok 2 - extracted 'PPI3_SYNY3'
ok 3 - extracted '276 aa'
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.