Here is a partial solution inspired by an earlier post with very little modification!
Assuming the input record separator is a "=====":
use strict; use Data::Dumper; my @seq; # array of sequences my %seq; # hash lookup of sequences based on id's { local $/ = '=========================================='; while (<DATA>) { s/^==========================================//g; # strip out '>' +from beginning s/==========================================$//g; # and end of line my $line = $_; next if !length($_); # ignore empty lines next if /^\n$/; my @a = split /\n/, $_; # collect lines in an array my @new_a = grep {$_ ne "" } @a ; # remove empty lines #s/^(.*)\n//; # and strip it out my @rec; s/\n/\t/mg; # join the sequence strings push @rec, @new_a; # push sequence into an array push @seq, \@rec; # push into array of sequences push @{ $seq{$new_a[1]} }, \@rec; # or store in a hash loo +kup } } print Dumper(\@seq); print Dumper(\%seq); __DATA__ ========================================== Log Entry 14: 27 Feb 2011 10:03:42 Alert Level 2: Informational Keyword: Type-02 127002 1208322 Soft Reset Logged by: Baseboard Management Controller; Sensor: System Event 0x204D6A217E0200F0 FFFF027000120300 ========================================== Log Entry 13: 20 Feb 2011 08:33:42 Alert Level 2: Informational Keyword: Type-02 127002 1208322 Soft Reset Logged by: Baseboard Management Controller; Sensor: System Event 0x204D60D1E60200E0 FFFF027000120300 ========================================== Log Entry 12: 20 Feb 2011 07:14:27 Alert Level 4: TEST ALERT!!!!!!!!!!!!!!!! Keyword: Type-02 127002 1208322 Soft Reset Logged by: Baseboard Management Controller; Sensor: System Event 0x204D60BF530200D0 FFFF027000120300 ========================================== Log Entry 11: 13 Feb 2011 07:24:32 Alert Level 5: TEST ALERT!!!!!!!!!!!!!!!!!!!! Keyword: Type-02 127002 1208322 Soft Reset Logged by: Baseboard Management Controller; Sensor: System Event 0x204D5787300200C0 FFFF027000120300 ========================================== Log Entry 10: 06 Feb 2011 10:36:26 Alert Level 2: Informational Keyword: Type-02 127002 1208322 Soft Reset Logged by: Baseboard Management Controller; Sensor: System Event 0x204D4E79AA0200B0 FFFF027000120300 ==========================================
Once you have it in a data structure as shown in the output, you can modify the code to insert text before and after based on the required specification.

In reply to Re^2: splice an array by umasuresh
in thread splice an array by dbs

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.