#!/usr/bin/perl
while(@data = <DATA>){
$au='';
$by='';
for($i=0;$i<$#data;$i++){
if($data[$i]=~ m/^\.\.AU/){
unless($data[$i+1]=~ /^\.\./){
$data[$i+1] =~ s/^\s+|\s+$//;
$au = $data[$i+1];
}
}
if($data[$i]=~ m/^\.\.BD/){
unless($data[$i+1]=~ /^\.\./){
$data[$i+1] =~ s/^\s+|\s+$//;
$by = $data[$i+1];
}
}
}
print "$au,$by";
}
__DATA__
..HD:
..SE:
..AU:
C
..BD:
ON PAC
..BD:
BY PK
..SE:
..AU:
R CHRIS
..BD:
ON PAC-20 FOOTBALL
..BD:
ON PAC-30 BASKETBALL
..AU:
DK
How to make a pair of AU and BD and print all the values.
If there are corresponding BD values how to concatenate with "," unless any other tag with matching with "..text:" is found.
If no BD is found for the corresponding "AU",, we should not add comma.
output should look like:
C,ON PAC,BY PK
R CHRIS,ON PAC-20 FOOTBALL,ON PAC-30 BASKETBALL
DK
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.