Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Extract Multiple Tags

by Cristoforo (Deacon)
on Dec 22, 2011 at 01:30 UTC ( #944718=note: print w/ replies, xml ) Need Help??


in reply to Extract Multiple Tags

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


Comment on Re: Extract Multiple Tags
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://944718]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (16)
As of 2015-07-31 13:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (278 votes), past polls