If it's not very large file, I think the simpliest way is to put the whole file into an string as explained
here.
Once done,
split and regex will do the rest of the work:
use strict;
use warnings;
my $text = <<EOF;
=================================================
Record 0
Name : John [John]
I/C : >123< [123]
Sex : 'Male' [Male]
Ref : >12< [12]
==================================================
Record 1
Name : Pretty [Pretty]
I/C : >125< [125]
Location : 'Female' [Female]
Ref : >12< [12]
==================================================
Record 2
Name : Kim [Kim]
I/C : >124< [124]
Location : 'Male' [Male]
Ref : >11< [11]
==================================================
EOF
my @goods = grep /Ref\s+:\s+>12</, split /=+/, $text;
# For this example
print join "\n==================================================\n",
+@goods;
Hope it helps,
deibyz
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.