Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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:#!/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
C,ON PAC,BY PK R CHRIS,ON PAC-20 FOOTBALL,ON PAC-30 BASKETBALL DK
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: match tags
by jethro (Monsignor) on Nov 09, 2009 at 10:53 UTC | |
|
Re: match tags
by arun_kom (Monk) on Nov 09, 2009 at 12:03 UTC | |
|
Re: match tags
by shmem (Chancellor) on Nov 09, 2009 at 16:19 UTC |