namelkcip has asked for the wisdom of the Perl Monks concerning the following question:
I have sample data such as:
I need to extract each object into its own hash that I'll then roll up into an AoH. I have tried changing the delimiter $/ but I think that can only be a static string and each 'object network' line finishes with a unique name. I couldn't find any way to make the delimiter regex based (which I think would solve my problem unless the delimiter is removed/consumed when parsing records). I next thought about reading the whole file to an array and processing records in line batches. However some objects have a description, making it a batch of 3 lines, whereas some don't making it a batch of 2. I suppose I could do some work processing the array to look for whether or not the line has a description, but I feel like I am way over-thinking this. I also tried to extract text between lines, but I don't have unique START/END variables like examples showing the use of range /START/ .. /END/. I tried anyways using a regex match looking for just text between groupings of /object network/ but that was exclusive/destructive and I began to lose records. I can post some code if necessary.object network Microsoft.Lync.Host.3 host 138.108.25.111 description Help Desk Ticket #476739 object network Microsoft.Lync.Host.4 host 138.108.25.112 description Help Desk Ticket #476739 object network Microsoft.Lync.Host.5 host 138.108.25.113 description Help Desk Ticket #476739 object network Microsoft.Lync.Host.6
I'm sure one of the Monks here has a solution! Thanks in advance.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Extract Data Between Lines
by wazat (Monk) on Apr 04, 2014 at 03:38 UTC | |
Re: Extract Data Between Lines
by Athanasius (Archbishop) on Apr 04, 2014 at 02:45 UTC | |
Re: Extract Data Between Lines
by LanX (Saint) on Apr 04, 2014 at 03:19 UTC | |
Re: Extract Data Between Lines
by LanX (Saint) on Apr 04, 2014 at 02:52 UTC | |
Re: Extract Data Between Lines
by kcott (Archbishop) on Apr 04, 2014 at 06:17 UTC | |
Re: Extract Data Between Lines
by hdb (Monsignor) on Apr 04, 2014 at 12:59 UTC | |
Re: Extract Data Between Lines
by namelkcip (Initiate) on Apr 04, 2014 at 14:31 UTC |
Back to
Seekers of Perl Wisdom