dbs has asked for the wisdom of the Perl Monks concerning the following question:
GOAL: insert new text before at a minimum and after a block of text ideally.
I put data in a file like so:
I am able to find any text entry "Alert Level 3" or higher, but then, I want to insert rtf code before this block of text and at the end of this block of text. I am failing on the insert before and insert after.while (<$RLOG>) { if (/(^Log Entry\s\d+:.*)/) { ++$recordcount; my $N = $1 .+ "\n\n"; my $e = <$RLOG>; my $x = <$RLOG>; my $t = <$RLOG>; my $l = <$RLOG>; my $n = <$RLOG>; my $s = <$RLOG> .+ "\n======================================== +==\n"; push @ary, ($N,$e,$x,$t,$l,$n,$s); } } for (@ary) { print $PLOG, $_; }
I tried using splice like so: splice( @ary, $pos, 0, $RTF{ctbl}, $RTF{red}, $RTF{ered} );while(<$PLOG>) { ++$alert3orMoreCount if /^Alert Level\s0*(?:[3-9]|\d{2,})/i; $pos = $. if /^Alert Level\s0*(?:[3-9]|\d{2,})/i; }
It seems silly to write the array data to a file, then try and manipulate it after. Below is the raw data file. Thank you!
__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 ==========================================
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: splice an array
by umasuresh (Hermit) on May 03, 2011 at 21:50 UTC | |
by umasuresh (Hermit) on May 04, 2011 at 12:49 UTC | |
|
Re: splice an array
by LanX (Saint) on May 03, 2011 at 22:06 UTC | |
by dbs (Sexton) on May 04, 2011 at 12:52 UTC | |
by toolic (Bishop) on May 04, 2011 at 13:01 UTC | |
by Anonymous Monk on May 04, 2011 at 13:24 UTC | |
by dbs (Sexton) on May 04, 2011 at 17:31 UTC | |
by dbs (Sexton) on May 04, 2011 at 17:48 UTC | |
by Anonymous Monk on May 04, 2011 at 12:57 UTC |