Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: splice an array

by umasuresh (Hermit)
on May 03, 2011 at 21:50 UTC ( [id://902770]=note: print w/replies, xml ) Need Help??


in reply to splice an array

It may be visually useful to indicate where exactly you want to insert text, something like:
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
Is the arrow heads where you want to insert the text?
UPDATE: got it, I misunderstood the question initially!

Replies are listed 'Best First'.
Re^2: splice an array
by umasuresh (Hermit) on May 04, 2011 at 12:49 UTC
    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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-18 14:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found