Here is an approach that worked on the data you provided. I think it would replace your
foreach loop.
Although, I'm not sure how you want your data printed with a '<br>' at the end of each line.
#!/usr/bin/perl
use strict;
use warnings;
use 5.014;
my ($file, $function, $tag);
printf "%-5s%-15s%s\n", qw/ Tags Function File /;
my @line = <DATA>;
for my $i (0 .. $#line) {
if ($line[$i] =~ /^File: (.+)$/) {
$file = $1;
}
elsif ($line[$i] =~ /^Function: (.+)$/) {
$function = $1;
}
elsif ($line[$i] =~ /^Tag: Yes$/) {
($tag) = $line[$i+1] =~ /(\d+)$/;
printf "%-5s%-15s%s\n", $tag, $function, $file;
}
}
__DATA__
File: check1.asm
Function: Monks
Tag: No
Tag: 001
Tag: Yes
Tag: 002
File: check2.asm
Function: Perl Monks
Tag: Yes
Tag: 003
Tag: No
Tag: 004
File: check3.asm
Function: Experts
Tag: No
Tag: 005
Tag: No
Tag: 006
Function: Perl Experts
Tag: No
Tag: 007
Tag: Yes
Tag: 008
Outputs
Tags Function File
002 Monks check1.asm
003 Perl Monks check2.asm
008 Perl Experts check3.asm
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.